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

Throw an error when the short flag for an option for longer than one character #937

Closed
HopefulLlama opened this issue Mar 26, 2019 · 4 comments

Comments

@HopefulLlama
Copy link

In the .option(...) method, it takes a string flag which is comma separated, and describes a short and a long flag for passing arguments, such as:

  .option('-v, --version', 'Version information');

However, when given a short flag which is longer than one character, the program will still parse and execute, but cannot be accessed by its short flag.

For example:

  .option('-nv, --next-version', 'The next version');

It is impossible to use -nv on the command-line, as commander interprets this as two short flags concatenated together: -n and -v.

It would be better to throw an error to avoid the misleading set up of commander options.

@shadowspawn
Copy link
Collaborator

The documentation does mention the cli behaviour:

Short flags may be passed as a single arg, for example -abc is equivalent to -a -b -c.

but I agree it would be nice if commander warned you about the setup problem.

@HopefulLlama
Copy link
Author

It does mention that, but it took me a long time to put two and two together.

I.e.: It does take some thinking to realise that a two character flag cannot work due to the short flag feature. It doesn't explicitly say so in the documentation.

I think an addition to the documentation, and an error or warning given when the misleading setup is actioned would be suitable.

@shadowspawn
Copy link
Collaborator

It now explicitly says single character in the documentation. (But still no warning about coding error, so feel free to keep this issue open.)

@shadowspawn
Copy link
Collaborator

Some more errors or warnings for coders (rather than users) is something we can improve in future. Closing this as have made an improvement with the addition to the README.

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