-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of displaying custom usage in subcommand list (#1896)
* Add example of displaying custom usage in subcommand list * Make example more focused
- Loading branch information
1 parent
4ef19fa
commit 7fe7831
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |