Exemplo n.º 1
0
        protected override void VisitOptionNode(OptionNode optionNode)
        {
            if (_innermostCommandResult !.Children.ResultFor(optionNode.Option) is null)
            {
                var optionResult = new OptionResult(
                    optionNode.Option,
                    optionNode.Token,
                    _innermostCommandResult
                    );

                _innermostCommandResult.Children.Add(optionResult);
            }
        }
Exemplo n.º 2
0
        private void ParseOptionArguments(OptionNode optionNode)
        {
            var argument = optionNode.Option.Argument;

            var contiguousTokens   = 0;
            var continueProcessing = true;

            while (More() &&
                   CurrentToken.Type == TokenType.Argument &&
                   continueProcessing)
            {
                if (IsFull(argument))
                {
                    if (contiguousTokens > 0)
                    {
                        return;
                    }

                    if (argument.Arity.MaximumNumberOfValues == 0)
                    {
                        return;
                    }
                }
                else if (argument.ValueType == typeof(bool))
                {
                    if (ArgumentConverter.ConvertObject(
                            argument,
                            argument.ValueType,
                            CurrentToken.Value,
                            _configuration.Resources) is FailedArgumentTypeConversionResult)
                    {
                        return;
                    }
                }

                optionNode.AddChildNode(
                    new OptionArgumentNode(
                        CurrentToken,
                        argument,
                        optionNode));

                IncrementCount(argument);

                contiguousTokens++;

                Advance();

                continueProcessing = optionNode.Option.AllowMultipleArgumentsPerToken;
            }
        }
Exemplo n.º 3
0
        private void ParseOptionArguments(OptionNode optionNode)
        {
            var argument = optionNode.Option.Argument;

            var contiguousTokens = 0;

            while (More() &&
                   CurrentToken.Type == TokenType.Argument)
            {
                if (IsFull(argument))
                {
                    if (contiguousTokens > 0)
                    {
                        return;
                    }

                    if (argument.Arity.MaximumNumberOfValues == 0)
                    {
                        return;
                    }
                }
                else if (argument.Type == typeof(bool))
                {
                    if (ArgumentConverter.ConvertObject(
                            argument,
                            argument.Type,
                            CurrentToken.Value) is FailedArgumentTypeConversionResult)
                    {
                        return;
                    }
                }

                optionNode.AddChildNode(
                    new OptionArgumentNode(
                        CurrentToken,
                        argument,
                        optionNode));

                IncrementCount(argument);

                contiguousTokens++;

                Advance();
            }
        }
Exemplo n.º 4
0
        private OptionNode?ParseOption(CommandNode parent)
        {
            if (CurrentToken.Type != TokenType.Option)
            {
                return(null);
            }

            OptionNode?optionNode = null;

            if (parent.Command.Children.GetByAlias(CurrentToken.Value) is IOption option)
            {
                optionNode = new OptionNode(CurrentToken, option, parent);

                Advance();

                ParseOptionArguments(optionNode);
            }

            return(optionNode);
        }