<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using EntryPoint.Common;
using EntryPoint.Parsing;
using EntryPoint.Arguments;
using EntryPoint.Commands;
using EntryPoint.Help;

namespace EntryPoint {

    /// <summary>
    /// The main API for EntryPoint
    /// </summary>
    public static class Cli {
        internal const string DASH_SINGLE = "-";
        internal const string DASH_DOUBLE = "--";

        // ** Parsing **

        /// <summary>
        /// Create and populate a CliArguments implementation from the command line args
        /// </summary>
        /// <typeparam name="A">The type of the CliArguments, which derives from BaseCliArguments</typeparam>
        /// <returns>A populated CliArguments instance</returns>
        public static A Parse<A>() where A : BaseCliArguments, new() {
            var args = Environment.GetCommandLineArgs();
            return Parse(new A(), args);
        }

        /// <summary>
        /// Create and populate an ApplicationOptions implementation
        /// </summary>
        /// <typeparam name="A">The type of the CliArguments, which derives from BaseCliArguments</typeparam>
        /// <param name="args">The CLI arguments input</param>
        /// <returns>A populated CliArguments instance</returns>
        public static A Parse<A>(string[] args) where A : BaseCliArguments, new() {
            return Parse(new A(), args);
        }

        /// <summary>
        /// Populate a given CliArguments instance
        /// </summary>
        /// <typeparam name="A">The type of the CliArguments, which derives from BaseCliArguments</typeparam>
        /// <param name="applicationOptions">The pre-instantiated CliArguments implementation</param>
        /// <param name="args">The CLI arguments input</param>
        /// <returns>A populated CliArguments instance</returns>
        public static A Parse<A>(A applicationOptions, string[] args) where A : BaseCliArguments {

            // Process inputs
            ArgumentModel model = new ArgumentModel(applicationOptions);
            var tokens = Tokeniser.MakeTokens(args);
            ParseResult parseResult = Parser.MakeParseResult(tokens, model);
            
            // Map results
            model = ArgumentMapper.MapOptions(model, parseResult);

            if (model.CliArguments.HelpInvoked) {
                model.HelpFacade.Execute();
            }

            return (A)model.CliArguments;
        }


        // ** Command Execution **

        /// <summary>
        /// Executes a CliCommands implementation
        /// </summary>
        /// <typeparam name="C">The type of the class implementing BaseCliCommands, which can be created with 0 arguments</typeparam>
        public static C Execute<C>() where C : BaseCliCommands, new() {
            return Execute(new C(), Environment.GetCommandLineArgs());
        }

        /// <summary>
        /// Executes a CliCommands implementation
        /// </summary>
        /// <typeparam name="C">The type of the class implementing BaseCliCommands, which can be created with 0 arguments</typeparam>
        /// <param name="args">The CLI arguments input</param>
        public static C Execute<C>(string[] args) where C : BaseCliCommands, new() {
            return Execute(new C(), args);
        }

        /// <summary>
        /// Executes a CliCommands implementation
        /// </summary>
        /// <typeparam name="C">The type of the class implementing BaseCliCommands</typeparam>
        /// <param name="commands">An instance of the class implementing BaseCliCommands</param>
        /// <param name="args">The CLI arguments input</param>
        public static C Execute<C>(C commands, string[] args) where C : BaseCliCommands {
            var model = new CommandModel(commands);
            model.Execute(args);
            return commands;
        }


        // ** Help **

        /// <summary>
        /// Generate and return a Help string for a given BaseCliArguments or BaseCliCommands instance
        /// </summary>
        /// <typeparam name="A">Custom implementation type of BaseCliArguments or BaseCliCommands which can be created with 0 arguments</typeparam>
        /// <returns>Help string</returns>
        public static string GetHelp<A>() where A : BaseHelpable, new() {
            return GetHelp(new A());
        }

        /// <summary>
        /// Generate and return a Help string for a given BaseCliArguments or BaseCliCommands instance
        /// </summary>
        /// <typeparam name="A">Custom implementation type of BaseCliArguments or BaseCliCommands</typeparam>
        /// <param name="applicationOptions">Instance of the custom BaseCliArguments or BaseCliCommands implementation</param>
        /// <returns>Help string</returns>
        public static string GetHelp<A>(A applicationOptions) where A : BaseHelpable {
            if (applicationOptions is BaseCliArguments) {
                return CliArgumentsHelp.Generate(
                    new ArgumentModel(applicationOptions as BaseCliArguments));
            }
            if (applicationOptions is BaseCliCommands) {
                return CliCommandsHelp.Generate(
                    new CommandModel(applicationOptions as BaseCliCommands));
            }
            throw new InvalidOperationException(
                $"Unknown {nameof(BaseHelpable)}: "
                + $"{applicationOptions.GetType().Name}");
        }
    }

}<commit_msg>Skip first element when getting Cli arguments from Environemtn<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using EntryPoint.Common;
using EntryPoint.Parsing;
using EntryPoint.Arguments;
using EntryPoint.Commands;
using EntryPoint.Help;

namespace EntryPoint {

    /// <summary>
    /// The main API for EntryPoint
    /// </summary>
    public static class Cli {
        internal const string DASH_SINGLE = "-";
        internal const string DASH_DOUBLE = "--";

        // ** Parsing **

        /// <summary>
        /// Create and populate a CliArguments implementation from the command line args
        /// </summary>
        /// <typeparam name="A">The type of the CliArguments, which derives from BaseCliArguments</typeparam>
        /// <returns>A populated CliArguments instance</returns>
        public static A Parse<A>() where A : BaseCliArguments, new() {
            return Parse(new A(), GetCliArgs());
        }

        /// <summary>
        /// Create and populate an ApplicationOptions implementation
        /// </summary>
        /// <typeparam name="A">The type of the CliArguments, which derives from BaseCliArguments</typeparam>
        /// <param name="args">The CLI arguments input</param>
        /// <returns>A populated CliArguments instance</returns>
        public static A Parse<A>(string[] args) where A : BaseCliArguments, new() {
            return Parse(new A(), args);
        }

        /// <summary>
        /// Populate a given CliArguments instance
        /// </summary>
        /// <typeparam name="A">The type of the CliArguments, which derives from BaseCliArguments</typeparam>
        /// <param name="applicationOptions">The pre-instantiated CliArguments implementation</param>
        /// <param name="args">The CLI arguments input</param>
        /// <returns>A populated CliArguments instance</returns>
        public static A Parse<A>(A applicationOptions, string[] args) where A : BaseCliArguments {

            // Process inputs
            ArgumentModel model = new ArgumentModel(applicationOptions);
            var tokens = Tokeniser.MakeTokens(args);
            ParseResult parseResult = Parser.MakeParseResult(tokens, model);
            
            // Map results
            model = ArgumentMapper.MapOptions(model, parseResult);

            if (model.CliArguments.HelpInvoked) {
                model.HelpFacade.Execute();
            }

            return (A)model.CliArguments;
        }


        // ** Command Execution **

        /// <summary>
        /// Executes a CliCommands implementation
        /// </summary>
        /// <typeparam name="C">The type of the class implementing BaseCliCommands, which can be created with 0 arguments</typeparam>
        public static C Execute<C>() where C : BaseCliCommands, new() {
            return Execute(new C(), GetCliArgs());
        }

        /// <summary>
        /// Executes a CliCommands implementation
        /// </summary>
        /// <typeparam name="C">The type of the class implementing BaseCliCommands, which can be created with 0 arguments</typeparam>
        /// <param name="args">The CLI arguments input</param>
        public static C Execute<C>(string[] args) where C : BaseCliCommands, new() {
            return Execute(new C(), args);
        }

        /// <summary>
        /// Executes a CliCommands implementation
        /// </summary>
        /// <typeparam name="C">The type of the class implementing BaseCliCommands</typeparam>
        /// <param name="commands">An instance of the class implementing BaseCliCommands</param>
        /// <param name="args">The CLI arguments input</param>
        public static C Execute<C>(C commands, string[] args) where C : BaseCliCommands {
            var model = new CommandModel(commands);
            model.Execute(args);
            return commands;
        }


        // ** Help **

        /// <summary>
        /// Generate and return a Help string for a given BaseCliArguments or BaseCliCommands instance
        /// </summary>
        /// <typeparam name="A">Custom implementation type of BaseCliArguments or BaseCliCommands which can be created with 0 arguments</typeparam>
        /// <returns>Help string</returns>
        public static string GetHelp<A>() where A : BaseHelpable, new() {
            return GetHelp(new A());
        }

        /// <summary>
        /// Generate and return a Help string for a given BaseCliArguments or BaseCliCommands instance
        /// </summary>
        /// <typeparam name="A">Custom implementation type of BaseCliArguments or BaseCliCommands</typeparam>
        /// <param name="applicationOptions">Instance of the custom BaseCliArguments or BaseCliCommands implementation</param>
        /// <returns>Help string</returns>
        public static string GetHelp<A>(A applicationOptions) where A : BaseHelpable {
            if (applicationOptions is BaseCliArguments) {
                return CliArgumentsHelp.Generate(
                    new ArgumentModel(applicationOptions as BaseCliArguments));
            }
            if (applicationOptions is BaseCliCommands) {
                return CliCommandsHelp.Generate(
                    new CommandModel(applicationOptions as BaseCliCommands));
            }
            throw new InvalidOperationException(
                $"Unknown {nameof(BaseHelpable)}: "
                + $"{applicationOptions.GetType().Name}");
        }


        // ** Internal Helpers **

        static string[] GetCliArgs() {
            return Environment.GetCommandLineArgs().Skip(1).ToArray();
        }
    }

}
{'fraction_non_alphanumeric': 0.10917225950782998, 'fraction_numerical': 0.0006263982102908277, 'mean_word_length': 2.2478930543446674, 'pattern_counts': {'":': 0, '<': 135, '<?xml version=': 0, '>': 135, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7111232', 'n_tokens_mistral': 2780, 'n_tokens_neox': 2651, 'n_words': 844}