Skip to content

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

Open
@jonsequitur

Description

@jonsequitur

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

var optionA = new Option<string>("-a") { Arity = ArgumentArity.ZeroOrOne };
var optionB = new Option<bool>("-b");
var optionC = new Option<bool>("-c");

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

var result = command.Parse("-a -bc"); // -> [ root [ -a ] [ -b <True> ] [ -c <True> ] ]
var optionA = new Option<string>("-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 <subcommand> ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions