Skip to content
Myr

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 file

Take it

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

line 1why, one step back
1import { Command } from 'commander';

Add example of displaying custom usage in subcommand list (#1896)John Geebefore adoption7fe7831

lines 2–8why, one step back
2
3// 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.8

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

line 9why, one step back
9const program = new Command().configureHelp({

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 10–11why, one step back
10 subcommandTerm: (cmd) => cmd.name() + ' ' + cmd.usage(),
11});

Add example of displaying custom usage in subcommand list (#1896)John Geebefore adoption7fe7831

line 12why, one step back
12

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 13–14why, one step back
13program
14 .command('make <FILENAME>')

Add example of displaying custom usage in subcommand list (#1896)John Geebefore adoption7fe7831

lines 15–20why, one step back
15 .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 back
21 .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 back
24

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 25–26why, one step back
25program
26 .command('serve <SERVICE>')

Add example of displaying custom usage in subcommand list (#1896)John Geebefore adoption7fe7831

lines 27–33why, one step back
27 .option('--port <PORTNUMBER>')
28 .description('example command with default simple usage');2930program.parse();3132// Try the following:33// node help-subcommands-usage help