internal CommandLineApplication(
            CommandLineApplication?parent,
            IHelpTextGenerator helpTextGenerator,
            CommandLineContext context)
        {
            _context                = context ?? throw new ArgumentNullException(nameof(context));
            Parent                  = parent;
            Options                 = new List <CommandOption>();
            Arguments               = new List <CommandArgument>();
            Commands                = new List <CommandLineApplication>();
            RemainingArguments      = new List <string>();
            _helpTextGenerator      = helpTextGenerator ?? throw new ArgumentNullException(nameof(helpTextGenerator));
            _handler                = DefaultAction;
            _validationErrorHandler = DefaultValidationErrorHandler;
            Out   = context.Console.Out;
            Error = context.Console.Error;
            SetContext(context);
            _services           = new Lazy <IServiceProvider>(() => new ServiceProvider(this));
            ValueParsers        = parent?.ValueParsers ?? new ValueParserProvider();
            _parserConfig       = new ParserConfig();
            _clusterOptions     = parent?._clusterOptions;
            UsePagerForHelpText = parent?.UsePagerForHelpText ?? false;

            _conventionContext = CreateConventionContext();

            if (Parent != null)
            {
                foreach (var convention in Parent._conventions)
                {
                    Conventions.AddConvention(convention);
                }
            }
        }
        internal CommandLineApplication(CommandLineApplication parent,
                                        IHelpTextGenerator helpTextGenerator,
                                        CommandLineContext context,
                                        bool throwOnUnexpectedArg)
        {
            _context = context ?? throw new ArgumentNullException(nameof(context));
            Parent   = parent;
            ThrowOnUnexpectedArgument = throwOnUnexpectedArg;
            Options                = new List <CommandOption>();
            Arguments              = new List <CommandArgument>();
            Commands               = new List <CommandLineApplication>();
            RemainingArguments     = new List <string>();
            HelpTextGenerator      = helpTextGenerator;
            Invoke                 = () => 0;
            ValidationErrorHandler = DefaultValidationErrorHandler;
            SetContext(context);
            _services           = new Lazy <IServiceProvider>(() => new ServiceProvider(this));
            ValueParsers        = parent?.ValueParsers ?? new ValueParserProvider();
            _clusterOptions     = parent?._clusterOptions;
            UsePagerForHelpText = parent?.UsePagerForHelpText ?? true;

            _conventionContext = CreateConventionContext();

            if (Parent != null)
            {
                foreach (var convention in Parent._conventions)
                {
                    Conventions.AddConvention(convention);
                }
            }
        }
Пример #3
0
        internal CommandLineApplication(CommandLineApplication parent,
                                        IHelpTextGenerator helpTextGenerator,
                                        CommandLineContext context,
                                        bool throwOnUnexpectedArg)
        {
            _context = context ?? throw new ArgumentNullException(nameof(context));
            Parent   = parent;
            ThrowOnUnexpectedArgument = throwOnUnexpectedArg;
            Options                = new List <CommandOption>();
            Arguments              = new List <CommandArgument>();
            Commands               = new List <CommandLineApplication>();
            RemainingArguments     = new List <string>();
            HelpTextGenerator      = helpTextGenerator;
            Invoke                 = () => 0;
            ValidationErrorHandler = DefaultValidationErrorHandler;
            SetContext(context);

            _conventionContext = CreateConventionContext();

            if (Parent != null)
            {
                foreach (var convention in Parent._conventions)
                {
                    Conventions.AddConvention(convention);
                }
            }
        }
 /// <summary>
 /// Configure the application before executing it.
 /// </summary>
 protected virtual void ConfigureApp()
 {
     Conventions.UseDefaultConventions();
     Conventions.AddConvention(new CommandLoggerConvention(ConsoleLogger));
     Conventions.AddConvention(new DefaultOptionsConvention());
     Conventions.AddConvention(new OptionsValuesFromEnvironmentVariablesConvention());
     Conventions.AddConvention(new EnforceNamingConvention());
 }