예제 #1
0
        public ParsingResult <IModeLauncher> Parse(string[] args, TextWriter standardWriter, TextWriter errorWriter)
        {
            if (args.Empty() || !_modeParsers.ContainsKey(args[0]))
            {
                return(GetMissingModeResult(args, standardWriter, errorWriter));
            }
            var mode    = _modeParsers[args[0]];
            var options = new OptionCollection <IModeLauncher> {
                BaseOptionsParser, mode
            };
            var result = options.Parse(args.Skip(1));
            ParsingResult <IModeLauncher> failedResult;

            if (!result.RemainingArgs.Any() && HandleBaseOptions(result.Get(BaseOptionsParser).Result, standardWriter, mode))
            {
                return(ParsingResult <IModeLauncher> .SuccessfulResult(new NullModeLauncher()));
            }

            if (!result.Validate(out failedResult))
            {
                errorWriter.WriteLine(failedResult.ErrorMessage);
                errorWriter.WriteLine();
                ShowHelp(errorWriter, mode);
                return(failedResult);
            }
            var runner = result.Get(mode).Result;

            return(ParsingResult <IModeLauncher> .SuccessfulResult(new ModeLauncher(runner, args, GetVersion(), mode.Name)));
        }
예제 #2
0
        public IParsingResult <CommonOptions> ParseCommonOptions(string[] args)
        {
            var options = new OptionCollection <IModeLauncher> {
                CommonOptionsParser
            };
            var result = options.Parse(args.Skip(1));

            return(result.Get(CommonOptionsParser));
        }