Skip to content

Commit 58b77e4

Browse files
authored
fix #1779 (#1780)
* fix #1779 * add issue reference comment
1 parent 4712b0c commit 58b77e4

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/System.CommandLine.Tests/ArgumentTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,51 @@ public void OnlyTake_can_pass_on_all_tokens_from_a_single_arity_argument_to_anot
718718

719719
result.GetValueForArgument(multiple).Should().BeEquivalentSequenceTo(1, 2, 3);
720720
}
721+
722+
723+
[Fact] //https://github.com/dotnet/command-line-api/issues/1779
724+
public void OnlyTake_can_pass_on_all_tokens_from_a_single_arity_argument_to_another_that_also_passes_them_all_on()
725+
{
726+
var first = new Argument<string>(name: "first", parse: ctx =>
727+
{
728+
ctx.OnlyTake(0);
729+
return null;
730+
})
731+
{
732+
Arity = ArgumentArity.ZeroOrOne
733+
};
734+
735+
var second = new Argument<string[]>(name: "second", parse: ctx =>
736+
{
737+
ctx.OnlyTake(0);
738+
return null;
739+
})
740+
{
741+
Arity = ArgumentArity.ZeroOrMore
742+
};
743+
744+
var third = new Argument<string[]>(name: "third", parse: ctx =>
745+
{
746+
ctx.OnlyTake(3);
747+
return new[] { "1", "2", "3" };
748+
})
749+
{
750+
Arity = ArgumentArity.ZeroOrMore
751+
};
752+
753+
var command = new RootCommand
754+
{
755+
first,
756+
second,
757+
third
758+
};
759+
760+
var result = command.Parse("1 2 3");
761+
762+
result.GetValueForArgument(first).Should().BeNull();
763+
result.GetValueForArgument(second).Should().BeEmpty();
764+
result.GetValueForArgument(third).Should().BeEquivalentSequenceTo("1", "2", "3");
765+
}
721766
}
722767

723768
protected override Symbol CreateSymbol(string name)

src/System.CommandLine/Parsing/ParseResultVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private void ValidateAndConvertArgumentResults(IReadOnlyList<Argument> arguments
256256
{
257257
for (var i = 0; i < arguments.Count; i++)
258258
{
259-
if (i > 0 && _argumentResults.Count > 1)
259+
if (i > 0 && _argumentResults.Count > i)
260260
{
261261
var previousArgumentResult = _argumentResults[i - 1];
262262

0 commit comments

Comments
 (0)