Beispiel #1
0
 private static ParserResult <object> MatchVerb(
     Func <IEnumerable <string>, IEnumerable <OptionSpecification>, Result <IEnumerable <Token>, Error> > tokenizer,
     IEnumerable <Tuple <Verb, Type> > verbs,
     IEnumerable <string> arguments,
     StringComparer nameComparer,
     bool ignoreValueCase,
     CultureInfo parsingCulture,
     bool autoHelp,
     bool autoVersion,
     IEnumerable <ErrorType> nonFatalErrors)
 {
     return(verbs.Any(a => nameComparer.Equals(a.Item1.Name, arguments.First()))
         ? InstanceBuilder.Build(
                Maybe.Just <Func <object> >(
                    () =>
                    verbs.Single(v => nameComparer.Equals(v.Item1.Name, arguments.First())).Item2.AutoDefault()),
                tokenizer,
                arguments.Skip(1),
                nameComparer,
                ignoreValueCase,
                parsingCulture,
                autoHelp,
                autoVersion,
                nonFatalErrors)
         : MakeNotParsed(verbs.Select(v => v.Item2), new BadVerbSelectedError(arguments.First())));
 }
        private static ParserResult <object> MatchVerb(
            Func <IEnumerable <string>, IEnumerable <OptionSpecification>, Result <IEnumerable <Token>, Error> > tokenizer,
            IEnumerable <Tuple <Verb, Type> > verbs,
            Tuple <Verb, Type> defaultVerb,
            IEnumerable <string> arguments,
            StringComparer nameComparer,
            bool ignoreValueCase,
            CultureInfo parsingCulture,
            bool autoHelp,
            bool autoVersion,
            IEnumerable <ErrorType> nonFatalErrors)
        {
            string firstArg = arguments.First();

            var verbUsed = verbs.FirstOrDefault(vt =>
                                                nameComparer.Equals(vt.Item1.Name, firstArg) ||
                                                vt.Item1.Aliases.Any(alias => nameComparer.Equals(alias, firstArg))
                                                );

            if (verbUsed == default)
            {
                return(MatchDefaultVerb(tokenizer, verbs, defaultVerb, arguments, nameComparer, ignoreValueCase, parsingCulture, autoHelp, autoVersion, nonFatalErrors));
            }
            return(InstanceBuilder.Build(
                       Maybe.Just <Func <object> >(
                           () => verbUsed.Item2.AutoDefault()),
                       tokenizer,
                       arguments.Skip(1),
                       nameComparer,
                       ignoreValueCase,
                       parsingCulture,
                       autoHelp,
                       autoVersion,
                       nonFatalErrors));
        }
Beispiel #3
0
 public static ParserResult <T> Build <T>(
     Func <T> factory,
     IEnumerable <string> arguments,
     StringComparer nameComparer,
     CultureInfo parsingCulture)
 {
     return(InstanceBuilder.Build(
                factory,
                (args, optionSpecs) =>
                Tokenizer.Tokenize(args, name => NameLookup.Contains(name, optionSpecs, nameComparer)),
                arguments,
                nameComparer,
                parsingCulture));
 }
 private static ParserResult <object> MatchVerb(
     Func <IEnumerable <string>, IEnumerable <OptionSpecification>, StatePair <IEnumerable <Token> > > tokenizer,
     IEnumerable <Tuple <Verb, Type> > verbs,
     IEnumerable <string> arguments,
     StringComparer nameComparer,
     CultureInfo parsingCulture)
 {
     return(verbs.Any(a => nameComparer.Equals(a.Item1.Name, arguments.First()))
         ? InstanceBuilder.Build(
                Maybe.Just <Func <object> >(() => verbs.Single(v => nameComparer.Equals(v.Item1.Name, arguments.First())).Item2.AutoDefault()),
                tokenizer,
                arguments.Skip(1),
                nameComparer,
                parsingCulture)
         : new NotParsed <object>(
                new NullInstance(),
                verbs.Select(v => v.Item2),
                new[] { new BadVerbSelectedError(arguments.First()) }));
 }
Beispiel #5
0
 private static ParserResult <object> MatchVerb(
     Func <IEnumerable <string>, IEnumerable <OptionSpecification>, Result <IEnumerable <Token>, Error> > tokenizer,
     IEnumerable <Tuple <Verb, Type> > verbs,
     IEnumerable <string> arguments,
     StringComparer nameComparer,
     CultureInfo parsingCulture,
     IEnumerable <ErrorType> nonFatalErrors)
 {
     verbs = verbs.Memorize();
     return(verbs.Any(a => nameComparer.Equals(a.Item1.Name, arguments.First()))
         ? InstanceBuilder.Build(
                verbs.Single(v => nameComparer.Equals(v.Item1.Name, arguments.First())).Item2,
                Maybe.Nothing <Func <object> >(),
                tokenizer,
                arguments.Skip(1),
                nameComparer,
                false,
                parsingCulture,
                nonFatalErrors)
         : MakeNotParsed(verbs.Select(v => v.Item2), new BadVerbSelectedError(arguments.First())));
 }