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
45 changes: 45 additions & 0 deletions src/System.CommandLine.Tests/ArgumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,51 @@ public void OnlyTake_can_pass_on_all_tokens_from_a_single_arity_argument_to_anot

result.GetValueForArgument(multiple).Should().BeEquivalentSequenceTo(1, 2, 3);
}


[Fact] //https://github.com/dotnet/command-line-api/issues/1779
public void OnlyTake_can_pass_on_all_tokens_from_a_single_arity_argument_to_another_that_also_passes_them_all_on()
{
var first = new Argument<string>(name: "first", parse: ctx =>
{
ctx.OnlyTake(0);
return null;
})
{
Arity = ArgumentArity.ZeroOrOne
};

var second = new Argument<string[]>(name: "second", parse: ctx =>
{
ctx.OnlyTake(0);
return null;
})
{
Arity = ArgumentArity.ZeroOrMore
};

var third = new Argument<string[]>(name: "third", parse: ctx =>
{
ctx.OnlyTake(3);
return new[] { "1", "2", "3" };
})
{
Arity = ArgumentArity.ZeroOrMore
};

var command = new RootCommand
{
first,
second,
third
};

var result = command.Parse("1 2 3");

result.GetValueForArgument(first).Should().BeNull();
result.GetValueForArgument(second).Should().BeEmpty();
result.GetValueForArgument(third).Should().BeEquivalentSequenceTo("1", "2", "3");
}
}

protected override Symbol CreateSymbol(string name)
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine/Parsing/ParseResultVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private void ValidateAndConvertArgumentResults(IReadOnlyList<Argument> arguments
{
for (var i = 0; i < arguments.Count; i++)
{
if (i > 0 && _argumentResults.Count > 1)
if (i > 0 && _argumentResults.Count > i)
{
var previousArgumentResult = _argumentResults[i - 1];

Expand Down