You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was using some examples from this repository to check if I can use commander in my application and I have a question.
Example: options-common.js program
Code:
const commander = require('commander');
const program = new commander.Command();
program
.option('-d, --debug', 'output extra debugging')
.option('-s, --small', 'small pizza size')
.option('-p, --pizza-type <type>', 'flavour of pizza');
program.parse(process.argv);
const options = program.opts();
if (options.debug) console.log(options);
console.log('pizza details:');
if (options.small) console.log('- small pizza size');
if (options.pizzaType) console.log(`- ${options.pizzaType}`);
The pizza-type option requires an argument, but if I do not add an argument and I use another option like -s, the pizza-type option use it as an argument.
My expectation was to receive the argument missing message. I want to add some checks in my code for the received argument, but I thought that the program would identify firstly that -s is another option, before verifying something else.
The text was updated successfully, but these errors were encountered:
This is intended behaviour, although surprising when you first encounter it and expect something different! It is the standard POSIX behaviour for options which have a required option-argument.
Quoting from different parts of the README (see the README for the associated code):
Options with an expected option-argument are greedy and will consume the following argument whatever the value. So --id -xyz reads -xyz as the option-argument.
Options with an optional option-argument are not greedy and will ignore arguments starting with a dash. So id behaves as a boolean option for --id -5, but you can use a combined form if needed like --id=-5.
I was using some examples from this repository to check if I can use commander in my application and I have a question.
Example: options-common.js program
Code:
The pizza-type option requires an argument, but if I do not add an argument and I use another option like
-s
, the pizza-type option use it as an argument.My expectation was to receive the argument missing message. I want to add some checks in my code for the received argument, but I thought that the program would identify firstly that
-s
is another option, before verifying something else.The text was updated successfully, but these errors were encountered: