Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 32 additions & 0 deletions src/System.CommandLine.Tests/ParsingValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,38 @@ public void When_a_required_argument_is_not_supplied_then_an_error_is_returned()
.Contain(e => e.Message == "Required argument missing for option: '-x'.");
}

[Fact]
public void When_an_IEnumerable_argument_has_zero_minimum_arity_and_no_tokens_GetRequiredValue_returns_empty()
{
var argument = new Argument<IEnumerable<string>>("items");
var command = new RootCommand { argument };

var result = command.Parse("");

result.Errors.Should().BeEmpty();
result.GetRequiredValue(argument).Should().BeEmpty();
}

[Fact]
public void When_an_IEnumerable_argument_has_OneOrMore_arity_and_no_tokens_then_an_error_is_returned()
{
var argument = new Argument<IEnumerable<string>>("items")
{
Arity = ArgumentArity.OneOrMore
};
var command = new RootCommand { argument };

var result = command.Parse("");

result.Errors
.Should()
.ContainSingle()
.Which
.Message
.Should()
.Contain("items");
}

[Fact]
public void When_a_required_option_is_not_supplied_then_an_error_is_returned()
{
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine/Parsing/SymbolResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public T GetRequiredValue<T>(Argument<T> argument)
=> GetResult(argument) switch
{
ArgumentResult argumentResult => argumentResult.GetValueOrDefault<T>(),
null => throw new InvalidOperationException($"{argument.Name} is required but was not provided."),
null => Argument<T>.CreateDefaultValue() ?? throw new InvalidOperationException($"{argument.Name} is required but was not provided."),
};

/// <inheritdoc cref="ParseResult.GetRequiredValue{T}(Option{T})"/>
Expand Down