tj / commander.js

node.js command-line interfaces made easy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to show a certain command's help info?

zzzgit opened this issue · comments

program.helpInformation() only return the help info for the top-level command.

How could I get the help info of the sub-command foo bar baz?

If you just want to display the help, you could call fooCmd.parse(['bar', 'help', 'baz'], { from: 'user' }). Note, this will exit the program.

To get the helpInformation() in code you will need to navigate down the cmd.commands tree yourself.

Zero error checking:

const info = fooCmd
    .commands.find(cmd => cmd.name() === 'bar')
    .commands.find(cmd => cmd.name() === 'baz')
    .helpInformation();

From the command-line, can display help with either of:

foo bar baz --help
foo bar help baz

An answer was provided, and no further activity in a month. Closing this as resolved.

Feel free to open a new issue if it comes up again, with new information and renewed interest.