Skip to content

Commit

Permalink
Add example of displaying custom usage in subcommand list (#1896)
Browse files Browse the repository at this point in the history
* Add example of displaying custom usage in subcommand list

* Make example more focused
  • Loading branch information
shadowspawn committed Jun 26, 2023
1 parent 4ef19fa commit 7fe7831
Showing 1 changed file with 29 additions and 0 deletions.
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

0 comments on commit 7fe7831

Please sign in to comment.