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

Add example of displaying custom usage in subcommand list #1896

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions examples/help-subcommands-usage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// const commander = require('commander'); // (normal include)
const commander = require('../'); // include commander in git clone of commander repo

// By default the subcommand list includes a fairly simple usage. If you have added a custom usage
// to the subcommands you may wish to configure the help to show these instead.
//
// See also ./configure-help.js which shows configuring the subcommand list to have no usage at all
// and just the subcommand name.

const program = new commander.Command()
.configureHelp({ subcommandTerm: (cmd) => cmd.name() + ' ' + cmd.usage() });

program.command('make <FILENAME>')
.usage('-root ROOTDIR [-abc] <FILENAME>')
.requiredOption('--root <ROOTDIR>')
.option('-a')
.option('-b')
.option('-c')
.summary('example command with custom usage')
.description('this full description is displayed in the full help and not in the list of subcommands');

program.command('serve <SERVICE>')
.option('--port <PORTNUMBER>')
.description('example command with default simple usage');

program.parse();

// Try the following:
// node help-subcommands-usage help