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 switches don't take numeric arguments #395

Closed
Sequoia opened this issue Apr 15, 2015 · 4 comments
Closed

short switches don't take numeric arguments #395

Sequoia opened this issue Apr 15, 2015 · 4 comments

Comments

@Sequoia
Copy link

Sequoia commented Apr 15, 2015

in minimist (or tail for that matter), -n10 sets n (or the switch it aliases) to 10.

A similar call with commander sets n (or the switch it aliases) to -1. This seems to mean a minimist to commander rewrite forces a CLI change, i.e. a cronjob that previously called foo -n10 will stop functioning properly if foo is upgraded from the minimist version to the commander version.

Is there a workaround? Am I mistaken?

@TheRoSS
Copy link
Contributor

TheRoSS commented Nov 17, 2016

The same issue.
commander.option("-c, --count <positiveInteger>", "...")
with call:
node myCoolScript -c2
gives:
commander.count = -2

@TheRoSS
Copy link
Contributor

TheRoSS commented Nov 17, 2016

This is a bug in the Command.prototype.normalize method
It is him who splits -c2345 option with parameter to a set of no parameter options -c -2 -3 -4 -5
Then parser behaves correctly and takes "correct" parameter for option "c"

@shadowspawn
Copy link
Collaborator

This issue will be partially resolved when v3.0.0 is released. Available now as a prerelease. See #1001

Support for passing option directly with short flags is added for recognised options (but not for options for subcommands with executable file as handler.)

@shadowspawn
Copy link
Collaborator

Support for directly appending values to short options has shipped in v3 (thanks @TheRoSS): https://github.com/tj/commander.js/releases/tag/v3.0.0

As per previous comment, currently only working for action handler based subcommands.

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

3 participants