dotnet / command-line-api

Command line parsing, invocation, and rendering of terminal output.
https://github.com/dotnet/command-line-api/wiki
MIT License
3.38k stars 380 forks source link

Add support for signalling the end of options #2433

Closed PonchoPowers closed 4 months ago

PonchoPowers commented 4 months ago

Support needs to be added for an option terminator to allow common *nix commands to be parsed correctly.

The following is an example of calling the node command in Windows.

node -h

Usage: node [options] [ script.js ] [arguments] node inspect [options] [ script.js | host:port ] [arguments]

Options: - script read from stdin (default if no file name is provided, interactive mode if a tty) -- indicate the end of node options

The snippet is cut short, to highlight the use of "--".

The following command shows why this is important... node --check -- --loader

The node command would perform a syntax check on the --loader file without executing it.

Such an implementation is common and widely supported in *nix environments, yet some node commands can't correctly be parsed with the current API.

elgonzo commented 4 months ago

System.CommandLine already does support the Posix -- end-of-options delimiter. Anything after the -- will be treated as ordinary argument values.

PonchoPowers commented 4 months ago

Yup sorry can see where it is defined now...

CliToken DoubleDash() => new("--", CliTokenType.DoubleDash, default, i);