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

Consider supporting POSIX, PowerShell, and Windows prefixes for all options by default #351

Open jonsequitur opened 5 years ago

jonsequitur commented 5 years ago

Many users have different expectations of command line syntax depending on which ecosystem they're used to.

It may help users if all prefixes "just work". For example, given the following code:

var myApp = new RootCommand("myapp");
myApp.AddOption(new Option("option"));

then the following command lines would be equivalent:

> myapp --option
> myapp -option
> myapp /option

The developer should retain the ability to opt out of this behavior, to specify exactly which prefixes they support, and to mix and match within one application. This is currently supported and should be retained.

These issues have a related motivation: #43, #133.

jonsequitur commented 5 years ago

@KathleenDollard @MarkMichaelis

KathleenDollard commented 5 years ago

Yes, yes, yes.

At least on first and third. The middle presents a problem in Posix, so I'm less confident on that being the default

Is your example --option or

--oz --panem --toon-town --interactive --narnia

Perhaps we could make this an error and have a way to communicate "Danger, danger" if the letters of an option could be a combination of other boolean options one letter aliases.

jonsequitur commented 5 years ago

During parser building we already throw if there are conflicting symbols.

zivkan commented 5 years ago

POSIX programs usually allow single character arguments to be provided in "batch" using a single switch. For example, the following are all equivalent:

> ls -lah
> ls -l -a -h
> ls -l --all --human-readable

If powershell style single - switches are used for multi-character aguments, does that mean that System.CommandLine by design will not support argument batching?

I haven't used either Linux or Powershell very much in my life, but I have used Linux a lot more than Powershell, so I personally prefer batched arguments over single switch multi-character arguments. But that's just my personal preference.

jonsequitur commented 5 years ago

@zivkan System.CommandLine supports the POSIX batching convention: https://github.com/dotnet/command-line-api/wiki/Syntax-Concepts-and-Parser#bundling.

In the case where abc is a valid token then that token would be chosen rather than unbundling into -a -b -c. We already perform a check before unbundling, e.g. each single character must be valid tokens for your program.