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

How do I implement $ program help command #205

Closed
MarcDiethelm opened this issue Apr 9, 2014 · 4 comments
Closed

How do I implement $ program help command #205

MarcDiethelm opened this issue Apr 9, 2014 · 4 comments

Comments

@MarcDiethelm
Copy link

I looked through the code and docs but don't understand how to get it to work.
There's a reference to this functionality at Command.prototype.addImplicitHelpCommand

But the method is marked as private, yet it's never called anywhere.

Either I just don't get it or this is a bug.

@tj
Copy link
Owner

tj commented Apr 25, 2014

our docs just suck, it's called for you when you do .command('subcommand', 'description here')

@MarcDiethelm
Copy link
Author

I tried for a long time to grok what what you are saying, digging through the code (and the errors) and thinking "man, this makes no sense."

Until I found this: https://github.com/visionmedia/commander.js/blob/master/examples/pm
Which tells me what I want is not actually implemented, and what is implemented is not what I want. What I was looking for is getting specific help for regular commands (not separate executables).

Put differently I want the two calls below to result in the same output.

$ program help command
$ program --help command

Which I finally got working like so:

program
    .command('help [command]')
    .description('Show usage information')
    .action(function(cmd) {
        'string' === typeof cmd
            ? program.emit(cmd, null, ['--help'])
            : program.outputHelp()
        ;
    });

Yeah, docs could be better. 👊

@aurora
Copy link

aurora commented Jan 7, 2015

Mmmm ... i really don't get it ... the "help" command does only seem to work when you make use of program.command('cmd', 'description'); but not for program.command('cmd').description('description'). I can't use the first variant, because the first variant requires the command to be a module file which i do not have and do not want in my case.

is there any reason this does not work for the second form other than that it's currently not implemented?

@shadowspawn
Copy link
Collaborator

The two forms supported by default in later versions of Commander are:

program help command
program command --help

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

4 participants