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

Help option does not display help when using requiredOption #1089

Closed
aminch opened this issue Nov 4, 2019 · 3 comments
Closed

Help option does not display help when using requiredOption #1089

aminch opened this issue Nov 4, 2019 · 3 comments
Assignees
Labels
bug Commander is not working as intended

Comments

@aminch
Copy link

aminch commented Nov 4, 2019

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
@shadowspawn shadowspawn added the bug Commander is not working as intended label Nov 4, 2019
@shadowspawn
Copy link
Collaborator

Thanks. Reproduced. That is a bug and not the intended behaviour.

@shadowspawn shadowspawn self-assigned this Nov 4, 2019
@shadowspawn
Copy link
Collaborator

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.

@shadowspawn
Copy link
Collaborator

Should be fixed in 4.0.1 which has been released. Thanks @aminch for report and clear description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Commander is not working as intended
Projects
None yet
Development

No branches or pull requests

2 participants