Ejemplo n.º 1
0
        protected override void Stop(SyntaxNode node)
        {
            var helpWasRequested =
                _innermostCommandResult
                ?.Children
                .Any(o => o.Symbol is HelpOption) == true;

            if (helpWasRequested)
            {
                return;
            }

            ValidateCommandHandler();

            PopulateDefaultValues();

            ValidateCommandResult();

            foreach (var optionResult in _rootCommandResult !.AllOptionResults)
            {
                ValidateAndConvertOptionResult(optionResult);
            }

            var argumentResults = _rootCommandResult !
                                  .AllArgumentResults
                                  .ToList();

            if (argumentResults.Count > 0)
            {
                var arguments = _innermostCommandResult !.Command.Arguments.ToArray();

                for (var i = 0; i < arguments.Length; i++)
                {
                    if (argumentResults.Count == i)
                    {
                        var nextArgument       = arguments[i];
                        var nextArgumentResult = new ArgumentResult(
                            nextArgument,
                            _innermostCommandResult);

                        var previousArgumentResult = argumentResults[i - 1];

                        var passedOnTokens = _innermostCommandResult.Tokens.Skip(previousArgumentResult.Tokens.Count);

                        foreach (var token in passedOnTokens)
                        {
                            if (nextArgumentResult.IsArgumentLimitReached)
                            {
                                break;
                            }
                            nextArgumentResult.AddToken(token);
                        }

                        argumentResults.Add(nextArgumentResult);

                        previousArgumentResult.Parent !.Children.Add(nextArgumentResult);

                        _rootCommandResult.AddToSymbolMap(nextArgumentResult);
                    }

                    var argumentResult = argumentResults[i];

                    ValidateAndConvertArgumentResult(argumentResult);

                    if (argumentResult.PassedOnTokens is {} &&
Ejemplo n.º 2
0
        protected override void Stop(SyntaxNode node)
        {
            for (var i = 0; i < _innermostCommandResult !.Children.Count; i++)
            {
                if (_innermostCommandResult !.Children[i].Symbol is HelpOption)
                {
                    return;
                }
            }

            ValidateCommandHandler();

            PopulateDefaultValues();

            ValidateCommandResult();

            foreach (var optionResult in _rootCommandResult !.AllOptionResults)
            {
                ValidateAndConvertOptionResult(optionResult);
            }

            var argumentResults = _rootCommandResult !
                                  .AllArgumentResults
                                  .ToList();

            if (argumentResults.Count > 0)
            {
                var arguments = _innermostCommandResult !.Command.Arguments;

                for (var i = 0; i < arguments.Count; i++)
                {
                    if (argumentResults.Count == i)
                    {
                        var nextArgument       = arguments[i];
                        var nextArgumentResult = new ArgumentResult(
                            nextArgument,
                            _innermostCommandResult);

                        var previousArgumentResult = argumentResults[i - 1];

                        var passedOnTokensCount = _innermostCommandResult.Tokens.Count;

                        for (var j = previousArgumentResult.Tokens.Count; j < passedOnTokensCount; j++)
                        {
                            var token = _innermostCommandResult.Tokens[j];

                            if (nextArgumentResult.IsArgumentLimitReached)
                            {
                                break;
                            }

                            nextArgumentResult.AddToken(token);
                        }

                        argumentResults.Add(nextArgumentResult);

                        previousArgumentResult.Parent !.Children.Add(nextArgumentResult);

                        _rootCommandResult.AddToSymbolMap(nextArgumentResult);
                    }

                    var argumentResult = argumentResults[i];

                    ValidateAndConvertArgumentResult(argumentResult);

                    if (argumentResult.PassedOnTokens is {} &&