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

unexpected negation when no space between option letter and integer parameter #1455

Closed
bentorkington opened this issue Jan 31, 2021 · 3 comments

Comments

@bentorkington
Copy link

the parser seems to negate an integer parameter whenever

  • a program command is added, and
  • and option to it is called without a space
program
.command('update [directory...]')
.option('-j, --jobs <max>', 'Limit concurrent downloads. Default 2', 2)
.action(async (directory, opts) => {
  console.log(`number of jobs to run: ${opts.jobs}`);
});
program.parse(process.argv);

Output:

$ ./commandertest.js update -j 4
number of jobs to run: 4
$ ./commandertest.js update -j4 
number of jobs to run: -4    ***** EXPECTED: 4 *****

If the command line is removed, this reversing of sign does not happen.

@shadowspawn
Copy link
Collaborator

What version of commander are you using? I am unable to reproduce this with commander v7 and your example program.

(Note: if you have an async action handler, you should be calling .parseAsync() rather than .parse(). Not an issue for this program!)

@shadowspawn
Copy link
Collaborator

shadowspawn commented Jan 31, 2021

Ah, I am guessing you are using a commander version below v5. Earlier versions did not have support for combining the option and option value into a single argument for a subcommand. Instead the short options were unconditionally expanded to separate short flags.

-j4 --> -j -4

Fixed in #1145

@bentorkington
Copy link
Author

Apologies, I thought I had updated but I was still stuck on an older version. Sorry for the invalid report, and thanks for the fast response.

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