pkgjs / parseargs

Polyfill of `util.parseArgs()`
Apache License 2.0
121 stars 9 forks source link

Syntax for combined short option and value #78

Closed shadowspawn closed 2 years ago

shadowspawn commented 2 years ago

For a type: string option I would like to support -sVALUE for consistency with POSIX compatible implementations.

But should we also support -s=VALUE?! Three reasons for suggesting = form:

Caveat: this makes the equals special, and in particular user wanting leading = on value would need to use -s =xxx or -s==xxx.

For interest, various libraries supporting both forms:


Taking a look at the reference specifications and implementations I identified in https://github.com/pkgjs/parseargs/issues/76.

POSIX

Utility Conventions

If the SYNOPSIS of a standard utility shows an option with a mandatory option-argument (as with [ -c option_argument] in the example), a conforming application shall use separate arguments for that option and its option-argument. However, a conforming implementation shall also permit applications to specify the option and option-argument in the same argument string without intervening characters.

GNU

Program Argument Syntax Conventions

An option and its argument may or may not appear as separate tokens. (In other words, the whitespace separating them is optional.) Thus, -o foo and -ofoo are equivalent.

getopts_long

For an option with a mandatory option-argument, -o foo and -ofoo are equivalent.

Commander

For an option with a mandatory option-argument, -o foo and -ofoo are equivalent.

Minimist

Has some complex cases about other syntax that are accepted after the short option, but the main syntax is for an option expecting an argument that -o foo and -o=foo are equivalent.

Yargs

Has some complex cases about other syntax that are accepted after the short option, but the main syntax is for an option expecting an argument that -o foo and -o=foo are equivalent.

ljharb commented 2 years ago

It’s super weird to use an equals sign with a short argument, even weirder than omitting one with a long argument. I’d prefer not to support it.

shadowspawn commented 2 years ago

Will reopen if becomes relevant again.