Hi,
I wanted to have one option required. Once I added one, the help message will no longer show unless you include the required option. I would have expected it to show the help.
I created some sample code, from one of your samples.
Test Code:
const commander = require("commander");
const program = new commander.Command();
program
.option("-d, --debug", "output extra debugging")
.requiredOption("-s, --small", "small pizza size")
.option("-p, --pizza-type <type>", "flavour of pizza");
program.parse(process.argv);
if (program.debug) console.log(program.opts());
console.log("pizza details:");
if (program.small) console.log("- small pizza size");
if (program.pizzaType) console.log(`- ${program.pizzaType}`);
Output:
$ node test.js -h
error: required option '-s, --small' not specified
If I remove the requiredOption I get the expected output:
$ node test.js -h
Usage: test [options]
Options:
-d, --debug output extra debugging
-s, --small small pizza size
-p, --pizza-type <type> flavour of pizza
-h, --help output usage information
Thanks. Reproduced. That is a bug and not the intended behaviour.
I consulted an old PR for the implementation pattern,and I thought it was a bit easy at the time! I have been untangling the command processing today and think I see a solid approach. Trying code now.
Should be fixed in 4.0.1 which has been released. Thanks @aminch for report and clear description.
Most helpful comment
Should be fixed in 4.0.1 which has been released. Thanks @aminch for report and clear description.