diff --git a/src/System.CommandLine.Tests/ParsingValidationTests.cs b/src/System.CommandLine.Tests/ParsingValidationTests.cs index f0e7fba9a9..523e982b08 100644 --- a/src/System.CommandLine.Tests/ParsingValidationTests.cs +++ b/src/System.CommandLine.Tests/ParsingValidationTests.cs @@ -170,6 +170,29 @@ public void When_FromAmong_is_used_for_multiple_arguments_and_invalid_input_is_p .Be(LocalizationResources.Instance.UnrecognizedArgument("not-value1", new[] { "value1", "value2" })); } + [Fact] + public void When_FromAmong_is_used_and_multiple_invalid_inputs_are_provided_the_error_mentions_first_invalid_argument() + { + Option option = new(new[] { "--columns" }); + option.AcceptOnlyFromAmong("author", "language", "tags", "type"); + option.Arity = new ArgumentArity(1, 4); + option.AllowMultipleArgumentsPerToken = true; + + var command = new Command("list") + { + option + }; + + var result = command.Parse("list --columns c1 c2"); + + // Currently there is no possibility for a single validator to produce multiple errors, + // so only the first one is checked. + result.Errors[0] + .Message + .Should() + .Be(LocalizationResources.Instance.UnrecognizedArgument("c1", new[] { "author", "language", "tags", "type" })); + } + [Fact] public void When_a_required_argument_is_not_supplied_then_an_error_is_returned() { diff --git a/src/System.CommandLine/Argument{T}.cs b/src/System.CommandLine/Argument{T}.cs index 7f49d98bd9..35c3d4204d 100644 --- a/src/System.CommandLine/Argument{T}.cs +++ b/src/System.CommandLine/Argument{T}.cs @@ -195,6 +195,7 @@ void UnrecognizedArgumentError(ArgumentResult argumentResult) if (Array.IndexOf(values, token.Value) < 0) { argumentResult.ErrorMessage = argumentResult.LocalizationResources.UnrecognizedArgument(token.Value, values); + break; } } }