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

using System.Collections.Generic;
using System.CommandLine.Parsing;
using System.CommandLine.Tests.Utility;
using System.IO;
using FluentAssertions;
using System.Linq;
Expand Down Expand Up @@ -692,6 +693,28 @@ public void OnlyTake_throws_when_called_twice()
.Should()
.Be("OnlyTake can only be called once.");
}

[Fact]
public void OnlyTake_can_pass_on_all_tokens()
{
var argument1 = new Argument<int[]>(result =>
{
result.OnlyTake(0);
return null;
});
var argument2 = new Argument<int[]>();
var command = new RootCommand
{
argument1,
argument2
};

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

result.GetValueForArgument(argument1).Should().BeEmpty();

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

protected override Symbol CreateSymbol(string name)
Expand Down
5 changes: 0 additions & 5 deletions src/System.CommandLine/Parsing/ArgumentResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ public void OnlyTake(int numberOfTokens)
throw new InvalidOperationException($"{nameof(OnlyTake)} can only be called once.");
}

if (numberOfTokens == 0)
{
return;
}

var passedOnTokensCount = _tokens.Count - numberOfTokens;

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