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

Show help text programmatically #70

Open
danguilherme opened this issue Sep 28, 2017 · 1 comment
Open

Show help text programmatically #70

danguilherme opened this issue Sep 28, 2017 · 1 comment

Comments

@danguilherme
Copy link

danguilherme commented Sep 28, 2017

Expose a method to show the help string whenever I want to, like it being the default command of my program.

Program would be something like:

program
  .version(package.version)
  .action(() => program.showHelp())
  .command('real command')
  .action((args, options, logger) => /* do stuff */);
program.parse(process.argv);

// ./myprog
/* ... prints help ... */

I managed to print the help text using the private _help function, but as it's private and not documented, I believe it's not good to stick to it.

@beorn
Copy link

beorn commented Aug 22, 2020

I agree, another way to do this is to make the help command the default command:

(await program.getAllCommands())
  .filter((cmd) => cmd.name === "help")[0]
  .default()

Yet another way could be to manually invoke the help command if you detect that no args were given.

It'd be great if all of these options should ideally be possible through a more documented API — maybe something like this?

program.commands.help.default() // set help command as default
program.commands.help.run() // run help command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants