Skip to content

Commit bcd1df5

Browse files
committed
fix #1609
1 parent 55d6172 commit bcd1df5

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/System.CommandLine.Tests/ParsingValidationTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,5 +1153,30 @@ public void Multiple_validators_on_the_same_argument_do_not_report_duplicate_err
11531153
.Should()
11541154
.Be("Wrong");
11551155
}
1156+
1157+
[Fact] // https://github.com/dotnet/command-line-api/issues/1609
1158+
internal void When_there_is_an_arity_error_then_further_errors_are_not_reported()
1159+
{
1160+
var option = new Option<string>("-o");
1161+
option.AddValidator(result =>
1162+
{
1163+
result.ErrorMessage = "OOPS";
1164+
}); //all good;
1165+
1166+
var command = new Command("comm")
1167+
{
1168+
option
1169+
};
1170+
1171+
var parseResult = command.Parse("comm -o");
1172+
1173+
parseResult.Errors
1174+
.Should()
1175+
.ContainSingle()
1176+
.Which
1177+
.Message
1178+
.Should()
1179+
.Be("Required argument missing for option: '-o'.");
1180+
}
11561181
}
11571182
}

src/System.CommandLine/Parsing/ParseResultVisitor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ private void ValidateAndConvertOptionResult(OptionResult optionResult)
437437
if (arityFailure is { })
438438
{
439439
AddErrorToResult(optionResult, new ParseError(arityFailure.ErrorMessage!, optionResult));
440+
return;
440441
}
441442

442443
if (optionResult.Option.HasValidators)

0 commit comments

Comments
 (0)