Esempio n. 1
0
        internal ArgumentParseFailedResult(Command command, ArgumentParserResult argumentParseResult)
        {
            Command               = command;
            Parameter             = argumentParseResult.Parameter;
            RawArguments          = argumentParseResult.RawArguments;
            Arguments             = argumentParseResult.Arguments;
            ArgumentParserFailure = argumentParseResult.ArgumentParserFailure ?? throw new ArgumentException("Argument parser failure must not be null.", nameof(argumentParseResult));
            Position              = argumentParseResult.FailurePosition;
            switch (argumentParseResult.ArgumentParserFailure)
            {
            case ArgumentParserFailure.UnclosedQuote:
                Reason = "A quotation mark was left unclosed.";
                break;

            case ArgumentParserFailure.UnexpectedQuote:
                Reason = "Encountered an unexpected quotation mark.";
                break;

            case ArgumentParserFailure.NoWhitespaceBetweenArguments:
                Reason = "Whitespace is required between arguments.";
                break;

            case ArgumentParserFailure.TooFewArguments:
                var missingParameters = Command.Parameters.SkipWhile(x => x != Parameter).Where(x => !x.IsOptional).Select(x => $"'{x}'").ToImmutableArray();
                Reason = $"Required {(missingParameters.Length == 1 ? "parameter" : "parameters")} " +
                         $"{string.Join(", ", missingParameters)} {(missingParameters.Length == 1 ? "is" : "are")} missing.";
                break;

            case ArgumentParserFailure.TooManyArguments:
                Reason = "Too many arguments provided.";
                break;
            }
        }
        internal ArgumentParseFailedResult(CommandContext context, ArgumentParserResult parserResult)
        {
            Command      = context.Command;
            RawArguments = context.RawArguments;
            ParserResult = parserResult;

            _lazyReason = new Lazy <string>(() => parserResult.GetFailureReason(), true);
        }