dotnet / dotnet/command-line-api

Make multiple arity option overflow behavior consistent with argument behavior

Open
#1,143 0 comments 0 reactions 0 assignees View on GitHub
Area-Parser and Binder bug
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

This currently works:

```csharp
var intsArg = new Argument();
var stringsArg = new Argument();

var root = new RootCommand
{
intsArg,
stringsArg
};

var result = root.Parse("1 2 3 four five");

var _ = new AssertionScope();

result.ValueForArgument(intsArg)
.Should()
.BeEquivalentTo(new[] { 1, 2, 3 },
options => options.WithStrictOrdering());

result.ValueForArgument(stringsArg)
.Should()
.Be("four");

result.UnparsedTokens.Should()
.ContainSingle()
.Which
.Should()
.Be("five");
```

This (with the change of `intArg` to `intsOption`) does not:

```csharp
var intsOption = new Option("-i");
var stringsArg = new Argument("arg");

var root = new RootCommand
{
intsOption,
stringsArg
};

var result = root.Parse("-i 1 2 3 four");

result.FindResultFor(intsOption)
.GetValueOrDefault()
.Should()
.BeEquivalentTo(new[] { 1, 2, 3 }, options => options.WithStrictOrdering());

result.FindResultFor(stringsArg)
.Should()
.Be("four");
```

It seems these should be consistent, although the fact that arguments are positional and options are not might make this unintuitive.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.