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

Short option name with single character or multiple characters have different result #2211

Closed
Brucedayton opened this issue Jun 12, 2024 · 5 comments

Comments

@Brucedayton
Copy link

Steps to reproduce:

  1. Have command with a required option argument with a short name (e.g -a).
  2. Have command with a required option argument with a short name (e.g -bc).
    Run the command with the option argument but with no space after the argument name (e.g commandname -asdf).
    Run the command with the option argument but with no space after the argument name (e.g commandname -bcd).

Actual result:

  1. Command runs and option argument -a has value "sdf".
  2. error: unknown option '-bcd'

Can short option with single character report the same error like issue 2?

@shadowspawn
Copy link
Collaborator

The simple answer is short options should be a single character. This is not currently treated as an immediate error, but may be in the future.

From the README:

Each option can have a short flag (single character) and a long name

And listed as explicitly deprecated:

Short option flags like -ws were never supported, but the old README did not make this clear. The README now states that short options are a single character.

@shadowspawn
Copy link
Collaborator

(Thanks for the clear description.)

@shadowspawn
Copy link
Collaborator

Can short option with single character report the same error like issue 2?

No, an option with a required option argument looks for a value with or without a space. So these are equivalent:

util -a AAA
util -aAAA

This is a widely supported syntax, although I do consider it an advanced syntax. When you don't know about it, the lack of an error for an unlucky typo can be surprising.

@Brucedayton
Copy link
Author

Thank you for the detailed explanation

@shadowspawn
Copy link
Collaborator

Closing in favour of #2235, adding an error for short flag longer than one character

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

No branches or pull requests

2 participants