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 doesn't work when using subcommands #110

Closed
andzdroid opened this issue Dec 12, 2012 · 7 comments
Closed

Help doesn't work when using subcommands #110

andzdroid opened this issue Dec 12, 2012 · 7 comments

Comments

@andzdroid
Copy link

Very simple test program:

var program = require('commander');
program
  .version('0.0.1')
  .command('test', 'test command')
  .parse(process.argv);

Save it as bla.js.

If we run node bla -h, we get this error:

bla--h(1) does not exist

Similar results if we use --help.

-V and --version work fine though.

I'm okay with it not working, since we can use bla help [cmd], but the help message lists -h and --help as options, and there is no way to turn that off.

@katanacrimson
Copy link

@andzdroid Just hit this problem, found out the cause and a fix. You need to change your .parse() line.

Don't chain it off of the previous lines, it'll chain off of the .command() instance. Directly use it as program.parse.

@andrew
Copy link

andrew commented Apr 14, 2013

@damianb can you show an example of how you got that working?

@katanacrimson
Copy link

change your last line, in your own example, to literally be program.parse(process.argv);

Don't chain it at all.

@andrew
Copy link

andrew commented Apr 14, 2013

I have:

#!/usr/bin/env node

var program = require('commander');

program
  .version('0.0.1')
  .command('config', 'show current config')
  .command('demo', 'perform a scripted demo')

program.parse(process.argv)

Still shows the --help option but calling it results in:

$ ./bin/nodecopter --help
execvp(): No such file or directory

  nodecopter---help(1) does not exist

@katanacrimson
Copy link

@andrew In practice, works for me - working example: https://github.com/damianb/blip/blob/master/bin/blip

@andrew
Copy link

andrew commented Apr 15, 2013

@fingerpich
Copy link

fingerpich commented May 20, 2018

I had the same problem but the following code works for me

var program = require('commander');
program
  .version('0.0.1');

program
  .command('test [name]')
  .description('test command')
  .action((name, cmd) => {
    ...
  });

program
  .parse(process.argv);

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

5 participants