Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/System.CommandLine.Tests/ParsingValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]> 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()
{
Expand Down
1 change: 1 addition & 0 deletions src/System.CommandLine/Argument{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ void UnrecognizedArgumentError(ArgumentResult argumentResult)
if (Array.IndexOf(values, token.Value) < 0)
{
argumentResult.ErrorMessage = argumentResult.LocalizationResources.UnrecognizedArgument(token.Value, values);
break;
}
}
}
Expand Down