Example #1
0
#pragma warning disable RECS0021 // Warns about calls to virtual member functions occuring in the constructor

        public Options(OptionsContext context)
        {
            Context = context;
            InitializeOtherDefaults();
            OptionParser = new OptionList(this, context);
            OptionParser.AdditionalBannerInfo = AdditionalBannerInfo;
        }
        public void Execute(IEnumerable <string> args, ErrorReporter ReportError)
        {
            var commandName = args.FirstOrDefault();

            if (!string.IsNullOrWhiteSpace(commandName))
            {
                foreach (var command in _commands)
                {
                    if (commandName.Equals(command.Name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        var parser = new OptionList(command, _context);
                        parser.DoHelp();
                        return;
                    }
                }
            }
            else
            {
                _optionParser.DoHelp(_commands);
            }
        }
        public void ProcessArgs(string[] args, Func <int, string[]> exitFunc)
        {
            var optionParser = new OptionList(this, Context, stopOnFirstNonOption: true);

            optionParser.AdditionalBannerInfo = AdditionalBannerInfo;
            if (args == null || args.Length == 0)
            {
                optionParser.DoHelp();
                return;
            }

            var helpCommand = new HelpCommand(AllCommands, optionParser, Context);

            AllCommands.Add(helpCommand);
            var commands = AllCommands.Distinct(this).OrderBy(command => command.Name.ToLowerInvariant()).ToList();

            AllCommands.Clear();
            AllCommands.AddRange(commands);

            var remainingArgs = optionParser.ProcessArgs(args, exitFunc);
            var commandName   = remainingArgs.FirstOrDefault();
            var commandArgs   = remainingArgs.Skip(1).ToArray();

            if (string.IsNullOrWhiteSpace(commandName))
            {
                optionParser.DoHelp();
                return;
            }

            foreach (var command in AllCommands)
            {
                if (commandName.Equals(command.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    var parser = new OptionList(command, Context);
                    parser.AdditionalBannerInfo = AdditionalBannerInfo;
                    command.Execute(parser.ProcessArgs(commandArgs, exitFunc), Context.ReportError);
                }
            }
        }
 public HelpCommand(List <ICommand> commands, OptionList optionParser, OptionsContext context)
 {
     _commands     = commands;
     _optionParser = optionParser;
     _context      = context;
 }