private AppliedOption TryTakeOptionOrCommand(Token token)
        {
            var childOption = appliedOptions
                              .SingleOrDefault(o =>
                                               o.Option.DefinedOptions
                                               .Any(oo => oo.RawAliases.Contains(token.Value)));

            if (childOption != null)
            {
                return(childOption.TryTakeToken(token));
            }

            if (token.Type == TokenType.Command &&
                appliedOptions.Any(o => o.Option.IsCommand && !o.HasAlias(token.Value)))
            {
                // if a subcommand has already been applied, don't accept this one
                return(null);
            }

            var applied =
                appliedOptions.SingleOrDefault(o => o.Option.HasRawAlias(token.Value));

            if (applied != null)
            {
                applied.OptionWasRespecified();
                return(applied);
            }

            applied =
                Option.DefinedOptions
                .Where(o => o.RawAliases.Contains(token.Value))
                .Select(o => new AppliedOption(o, token.Value))
                .SingleOrDefault();

            if (applied != null)
            {
                appliedOptions.Add(applied);
            }

            return(applied);
        }
Exemple #2
0
        private AppliedOption TryTakeOptionOrCommand(Token token)
        {
            var childOption = appliedOptions
                              .SingleOrDefault(o =>
                                               o.Option.DefinedOptions
                                               .Any(oo => oo.RawAliases.Contains(token.Value)));

            if (childOption != null)
            {
                return(childOption.TryTakeToken(token));
            }

            if (token.Type == TokenType.Command &&
                appliedOptions.Any(o => o.Option.IsCommand && !o.HasAlias(token.Value)))
            {
                return(null);
            }

            var applied =
                appliedOptions.SingleOrDefault(o => o.HasAlias(token.Value));

            if (applied != null)
            {
                return(applied);
            }

            applied =
                Option.DefinedOptions
                .Where(o => o.RawAliases.Contains(token.Value))
                .Select(o => new AppliedOption(o, token.Value))
                .SingleOrDefault();

            if (applied != null)
            {
                appliedOptions.Add(applied);
            }

            return(applied);
        }