dotnet / dotnet/command-line-api

Should option tokens be greedy with regard to subsequent bundled option or subcommand tokens?

Open
#1,380 1 comment 0 reactions 0 assignees View on GitHub
needs discussion
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

Currently, the token following a known option token is not treated as an argument. This means that if the subsequent token matches a subcommand, it will be treated as a subcommand

```cs
var optionA = new Option("-a") { Arity = ArgumentArity.ZeroOrOne };
var optionB = new Option("-b");
var optionC = new Option("-c");

var command = new RootCommand
{
optionA,
optionB,
optionC
};

var result = command.Parse("-a -bc"); // -> [ root [ -a ] [ -b ] [ -c ] ]
```

```cs
var optionA = new Option("-a");
var root = new RootCommand
{
new Command("subcommand"),
optionA
};

var result = root.Parse("-a subcommand"); // -> [ root [ -a ] [ subcommand ] ]
```

Should this behavior be changed so that the subsequent token would be considered an argument to the option, producing the following results, respectively, for the above examples?

```
[ root [ -a <-bc> ]
[ root [ -a ]
```

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.