internal ParseResult(
            Parser parser,
            RootCommandResult rootCommandResult,
            CommandResult commandResult,
            IDirectiveCollection directives,
            TokenizeResult tokenizeResult,
            IReadOnlyCollection <string> unparsedTokens,
            IReadOnlyCollection <string> unmatchedTokens,
            List <ParseError>?errors = null,
            string?rawInput          = null)
        {
            Parser             = parser;
            _rootCommandResult = rootCommandResult;
            CommandResult      = commandResult;
            Directives         = directives;

            // skip the root command
            Tokens = tokenizeResult.Tokens.Skip(1).ToArray();

            UnparsedTokens  = unparsedTokens;
            UnmatchedTokens = unmatchedTokens;

            RawInput = rawInput;

            _errors = errors ?? new List <ParseError>();

            if (parser.Configuration.RootCommand.TreatUnmatchedTokensAsErrors)
            {
                _errors.AddRange(
                    unmatchedTokens.Select(token =>
                                           new ParseError(parser.Configuration.ValidationMessages.UnrecognizedCommandOrArgument(token))));
            }
        }
Esempio n. 2
0
        protected override void VisitRootCommandNode(RootCommandNode rootCommandNode)
        {
            _rootCommandResult = new RootCommandResult(
                rootCommandNode.Command,
                rootCommandNode.Token);
            _rootCommandResult.ValidationMessages = _parser.Configuration.ValidationMessages;

            _innermostCommandResult = _rootCommandResult;
        }
Esempio n. 3
0
        internal ParseResult(
            Parser parser,
            RootCommandResult rootCommandResult,
            CommandResult commandResult,
            IDirectiveCollection directives,
            TokenizeResult tokenizeResult,
            IReadOnlyList <Token>?unparsedTokens,
            IReadOnlyList <Token>?unmatchedTokens,
            List <ParseError>?errors,
            string?commandLineText = null)
        {
            Parser             = parser;
            _rootCommandResult = rootCommandResult;
            CommandResult      = commandResult;
            Directives         = directives;

            // skip the root command when populating Tokens property
            if (tokenizeResult.Tokens.Count > 1)
            {
                var tokens = new Token[tokenizeResult.Tokens.Count - 1];
                for (var i = 0; i < tokenizeResult.Tokens.Count - 1; i++)
                {
                    var token = tokenizeResult.Tokens[i + 1];
                    tokens[i] = token;
                }

                Tokens = tokens;
            }
            else
            {
                Tokens = Array.Empty <Token>();
            }

            _unparsedTokens = unparsedTokens ?? Array.Empty <Token>();
            _errors         = errors ?? new List <ParseError>();
            CommandLineText = commandLineText;

            if (unmatchedTokens is null)
            {
                _unmatchedTokens = Array.Empty <Token>();
            }
            else
            {
                _unmatchedTokens = unmatchedTokens;

                if (parser.Configuration.RootCommand.TreatUnmatchedTokensAsErrors)
                {
                    for (var i = 0; i < _unmatchedTokens.Count; i++)
                    {
                        var token = _unmatchedTokens[i];
                        _errors.Add(new ParseError(parser.Configuration.LocalizationResources.UnrecognizedCommandOrArgument(token.Value), rootCommandResult));
                    }
                }
            }
        }
Esempio n. 4
0
        internal ParseResult(
            Parser parser,
            RootCommandResult rootCommandResult,
            CommandResult commandResult,
            IDirectiveCollection directives,
            TokenizeResult tokenizeResult,
            IReadOnlyList <Token> unparsedTokens,
            IReadOnlyList <Token> unmatchedTokens,
            List <ParseError>?errors = null,
            string?rawInput          = null)
        {
            Parser             = parser;
            _rootCommandResult = rootCommandResult;
            CommandResult      = commandResult;
            Directives         = directives;

            // skip the root command when populating Tokens property
            if (tokenizeResult.Tokens.Count > 1)
            {
                var tokens = new Token[tokenizeResult.Tokens.Count - 1];
                for (var i = 0; i < tokenizeResult.Tokens.Count - 1; i++)
                {
                    var token = tokenizeResult.Tokens[i + 1];
                    tokens[i] = token;
                }
                Tokens = tokens;
            }
            else
            {
                Tokens = Array.Empty <Token>();
            }

            _unparsedTokens  = unparsedTokens;
            _unmatchedTokens = unmatchedTokens;

            RawInput = rawInput;

            _errors = errors ?? (parser.Configuration.RootCommand.TreatUnmatchedTokensAsErrors
                                     ? new List <ParseError>(unmatchedTokens.Count)
                                     : new List <ParseError>());

            if (parser.Configuration.RootCommand.TreatUnmatchedTokensAsErrors)
            {
                for (var i = 0; i < unmatchedTokens.Count; i++)
                {
                    var token = unmatchedTokens[i];
                    _errors.Add(new ParseError(parser.Configuration.ValidationMessages.UnrecognizedCommandOrArgument(token.Value)));
                }
            }
        }
Esempio n. 5
0
 protected override void VisitRootCommandResult(RootCommandResult rootCommandResult)
 {
     CommandResults.Add(rootCommandResult.Command, rootCommandResult);
 }