Ejemplo n.º 1
0
        public (CommandTree tree, ILookup <string, string> remaining) Parse(IEnumerable <string> args)
        {
            var tokens  = Tokenizer.Tokenize(args);
            var context = new CommandTreeParserContext();

            var result = (CommandTree)null;

            if (tokens.Count > 0)
            {
                var token = tokens.Current;
                if (token.TokenType != Token.Type.String)
                {
                    if (_help != null)
                    {
                        if (_help.ShortName?.Equals(token.Value, StringComparison.Ordinal) == true ||
                            _help.LongName?.Equals(token.Value, StringComparison.Ordinal) == true)
                        {
                            // Show help
                            return(null, context.GetRemainingArguments());
                        }
                    }
                    throw new CommandAppException($"Unexpected option '{token.Value}'.");
                }
                result = ParseCommand(context, _configuration, null, tokens);
            }

            return(result, context.GetRemainingArguments());
        }