help-subcommands-usage.js
This file
Path
examples/help-subcommands-usage.js
33 lines · 1009 bytes · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
line 1why, one step back1import { Command } from 'commander';Add example of displaying custom usage in subcommand list (#1896)John Geebefore adoption7fe7831
lines 2–8why, one step back23// By default the subcommand list includes a fairly simple usage. If you have added a custom usage4// to the subcommands you may wish to configure the help to show these instead.5//6// See also ./configure-help.js which shows configuring the subcommand list to have no usage at all7// and just the subcommand name.8Switching to esm-only (#2464)John Geebefore adoptionf4bd470
line 9why, one step back9const program = new Command().configureHelp({Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 10–11why, one step back10 subcommandTerm: (cmd) => cmd.name() + ' ' + cmd.usage(),11});Add example of displaying custom usage in subcommand list (#1896)John Geebefore adoption7fe7831
line 12why, one step back12Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 13–14why, one step back13program14 .command('make <FILENAME>')Add example of displaying custom usage in subcommand list (#1896)John Geebefore adoption7fe7831
lines 15–20why, one step back15 .usage('-root ROOTDIR [-abc] <FILENAME>')16 .requiredOption('--root <ROOTDIR>')17 .option('-a')18 .option('-b')19 .option('-c')20 .summary('example command with custom usage')Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 21–23why, one step back21 .description(22 'this full description is displayed in the full help and not in the list of subcommands',23 );Add example of displaying custom usage in subcommand list (#1896)John Geebefore adoption7fe7831
line 24why, one step back24Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 25–26why, one step back25program26 .command('serve <SERVICE>')Add example of displaying custom usage in subcommand list (#1896)John Geebefore adoption7fe7831
lines 27–33why, one step back27 .option('--port <PORTNUMBER>')28 .description('example command with default simple usage');2930program.parse();3132// Try the following:33// node help-subcommands-usage help