Command-line-api: Consider supporting POSIX, PowerShell, and Windows prefixes for all options by default

Created on 23 Dec 2018  路  5Comments  路  Source: dotnet/command-line-api

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.

Area-API Area-Parser and Model Binder needs discussion

Most helpful comment

@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.

All 5 comments

@KathleenDollard @MarkMichaelis

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.

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

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.

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlgorithmsAreCool picture AlgorithmsAreCool  路  6Comments

erichiller picture erichiller  路  3Comments

divinebovine picture divinebovine  路  3Comments

SirJosh3917 picture SirJosh3917  路  3Comments

adamsitnik picture adamsitnik  路  5Comments