Skip to content

Make it possible for commands like dnx <toolname> to 'accrue' all tokens after <argname> for forwarding, not option-processing #2760

@baronfel

Description

@baronfel

Today in the .NET CLI experience, we have a feature that allows executing .NET Tools - .NET applications that are delivered via NuGet packages that the .NET CLI tooling can acquire on-demand or before execution. The command-line experience for these commands is structured something like the following:

Command("dnx")
  - Option<string[]>("--source") // for NuGet sources to get the packages from
  - Option<bool>("--interactive") // if nuget auth/other interactive experiences can be used in this interaction
  - Argument<string>("toolPackageName") // name of the NuGet package containing the tool command to run
  - Argument<string[]>("toolArgs") // arguments to forward to the tool command when run

and users use this command like the following:

dnx --source https://api.nuget.org/v3/index.json --interactive myTool -a 1 -b 2 -c --help

Today, as System.CommandLine processes each Token during Parsing, it classifies the --help token as belonging to the --help option that is provided by default as a recursive option, in this case coming from the dotnet RootCommand that hosts the implementation of the dnx command.

This is confusing to users, as they interpret the above command as

Token Option/Argument it belongs to
(dotnet) dnx dnx Command under the Dotnet RootCommand
--source --source Option
https://api.nuget.org/v2/index.json Argument of the --source Option
--interactive --interactive Option
myTool toolPackageName Argument
-a toolArgs Argument, position 0
1 toolArgs Argument, position 1
-b toolArgs Argument, position 2
2 toolArgs Argument, position 3
-c toolArgs Argument, position 4
--help toolArgs Argument, position 5

Users can force this behavior today if they invoke the above command like so:

dnx --source https://api.nuget.org/v3/index.json --interactive myTool -- -a 1 -b 2 -c --help

But to many users this is foreign - why can't the parser detect that anything after myTool should be treated as an argument to the tool?

Proposal

It should be possible to mark an Argument as greedy, or final, or some other semantic, and after the parser processes this argument every subsequent token, regardless of TokenType, would be aggregated into an IEnumerable<string> Argument (or similar collection-typed Argument) as if -- were inserted into the token stream.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions