diff --git a/examples/help-subcommands-usage.js b/examples/help-subcommands-usage.js new file mode 100644 index 000000000..a2f71476f --- /dev/null +++ b/examples/help-subcommands-usage.js @@ -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 ') + .usage('-root ROOTDIR [-abc] ') + .requiredOption('--root ') + .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 ') + .option('--port ') + .description('example command with default simple usage'); + +program.parse(); + +// Try the following: +// node help-subcommands-usage help