Skip to content

Syntax for combined short option and value #78

Closed
@shadowspawn

Description

@shadowspawn

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:

  • works in zero-config which otherwise does not have a way to specify option-argument for a short option
  • symmetry with --string=value
  • same syntax as some other libraries, like minimist and yargs

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

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