Skip to content

Commit a98bee2

Browse files
committed
add support ... or, uh, remove non-support ... for OnlyTake(0)
1 parent c2a4654 commit a98bee2

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/System.CommandLine.Tests/ArgumentTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections.Generic;
55
using System.CommandLine.Parsing;
6+
using System.CommandLine.Tests.Utility;
67
using System.IO;
78
using FluentAssertions;
89
using System.Linq;
@@ -692,6 +693,28 @@ public void OnlyTake_throws_when_called_twice()
692693
.Should()
693694
.Be("OnlyTake can only be called once.");
694695
}
696+
697+
[Fact]
698+
public void OnlyTake_can_pass_on_all_tokens()
699+
{
700+
var argument1 = new Argument<int[]>(result =>
701+
{
702+
result.OnlyTake(0);
703+
return null;
704+
});
705+
var argument2 = new Argument<int[]>();
706+
var command = new RootCommand
707+
{
708+
argument1,
709+
argument2
710+
};
711+
712+
var result = command.Parse("1 2 3");
713+
714+
result.GetValueForArgument(argument1).Should().BeEmpty();
715+
716+
result.GetValueForArgument(argument2).Should().BeEquivalentSequenceTo(1, 2, 3);
717+
}
695718
}
696719

697720
protected override Symbol CreateSymbol(string name)

src/System.CommandLine/Parsing/ArgumentResult.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ public void OnlyTake(int numberOfTokens)
6464
throw new InvalidOperationException($"{nameof(OnlyTake)} can only be called once.");
6565
}
6666

67-
if (numberOfTokens == 0)
68-
{
69-
return;
70-
}
71-
7267
var passedOnTokensCount = _tokens.Count - numberOfTokens;
7368

7469
PassedOnTokens = new List<Token>(_tokens.GetRange(numberOfTokens, passedOnTokensCount));

0 commit comments

Comments
 (0)