private CommandTree ParseCommand(
            CommandTreeParserContext context,
            ICommandContainer current,
            CommandTree parent,
            TokenStream stream)
        {
            context.ResetArgumentPosition();

            // Find the command.
            var commandToken = stream.Consume(Token.Type.String);
            var command      = current.FindCommand(commandToken.Value);

            if (command == null)
            {
                throw new CommandAppException($"Unknown command '{commandToken.Value}'.");
            }

            var node = new CommandTree(parent, command);

            while (stream.Peek() != null)
            {
                var token = stream.Peek();
                switch (token.TokenType)
                {
                case Token.Type.LongOption:
                    // Long option
                    ParseOption(context, stream, node, true);
                    break;

                case Token.Type.ShortOption:
                    // Short option
                    ParseOption(context, stream, node, false);
                    break;

                case Token.Type.String:
                    // Command
                    ParseString(context, stream, node);
                    break;

                default:
                    throw new InvalidOperationException("Unknown token type.");
                }
            }

            // Add unmapped parameters.
            foreach (var parameter in node.Command.Parameters)
            {
                if (node.Mapped.All(m => m.Item1 != parameter))
                {
                    node.Unmapped.Add(parameter);
                }
            }

            return(node);
        }
示例#2
0
        private CommandTree ParseCommand(
            CommandTreeParserContext context,
            ICommandContainer current,
            CommandTree parent,
            CommandTreeTokenStream stream)
        {
            // Find the command.
            var commandToken = stream.Consume(CommandTreeToken.Kind.String);
            var command      = current.FindCommand(commandToken.Value);

            if (command == null)
            {
                throw ParseException.UnknownCommand(_configuration, parent, context.Arguments, commandToken);
            }

            return(ParseCommandParameters(context, command, parent, stream));
        }
示例#3
0
    private CommandTree ParseCommand(
        CommandTreeParserContext context,
        ICommandContainer current,
        CommandTree?parent,
        CommandTreeTokenStream stream)
    {
        // Find the command.
        var commandToken = stream.Consume(CommandTreeToken.Kind.String);

        if (commandToken == null)
        {
            throw new CommandRuntimeException("Could not consume token when parsing command.");
        }

        var command = current.FindCommand(commandToken.Value, CaseSensitivity);

        if (command == null)
        {
            throw CommandParseException.UnknownCommand(_configuration, parent, context.Arguments, commandToken);
        }

        return(ParseCommandParameters(context, command, parent, stream));
    }