Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax for combined short option and value #78

Closed
shadowspawn opened this issue Mar 10, 2022 · 2 comments
Closed

Syntax for combined short option and value #78

shadowspawn opened this issue Mar 10, 2022 · 2 comments

Comments

@shadowspawn
Copy link
Collaborator

shadowspawn commented Mar 10, 2022

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.

@ljharb
Copy link
Member

ljharb commented Mar 10, 2022

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 added a commit that referenced this issue Mar 12, 2022
…ined short and value (#75)


1) Refactor parsing to use independent blocks of code, rather than nested cascading context. This makes it easier to reason about the behaviour.

2) Split out small pieces of logic to named routines to improve readability, and allow extra documentation and examples without cluttering the parsing. (Thanks to @aaronccasanova for inspiration.)

3) Existing tests untouched to make it clear that the tested functionality has not changed.

4) Be more explicit about short option group expansion, and ready to throw error in strict mode for string option in the middle of the argument. (See #11 and #74.)

5) Add support for short option combined with value (without intervening `=`). This is what Commander and Open Group Utility Conventions do, but is _not_ what Yargs does. I don't want to block PR on this and happy to comment it out for further discussion if needed. (I have found some interesting variations in the wild.) [Edit: see also #78]

6) Add support for multiple unit tests files. Expand tests from 33 to 113, but many for internal routines rather than testing exposed API.

7) Added `.editorconfig` file


Co-authored-by: Jordan Harband <[email protected]>
Co-authored-by: Aaron Casanova <[email protected]>
@shadowspawn
Copy link
Collaborator Author

Will reopen if becomes relevant again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants