Skip to content
Myr

Make examples more consistent with "Try the following" (#1629)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by John Gee · committed by GitHub · parent 43f4743 · Browse files · 20 files+87 added−78 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

20 files+87 added−78 removed

  • other:+87 added−78 removed

20 files+87 added−78 removed

modified:examples/arguments-extra.js+4 added-4 removed
modified:examples/configure-help.js+1 added-1 removed
modified:examples/configure-output.js+4 added-4 removed
modified:examples/custom-help+1 added-1 removed
16 unmodified lines
1718program.parse(process.argv);1920// Try the following:21// node custom-help --help21// node custom-help --help
modified:examples/custom-help-description+2 added-2 removed
19 unmodified lines
2021program.parse(process.argv);2223// Try the following:24// node custom-help-description -c25// node custom-help-description child --HELP24// node custom-help-description -c25// node custom-help-description child --HELP
modified:examples/custom-help-text.js+3 added-3 removed
modified:examples/custom-version+2 added-2 removed
12 unmodified lines
1314program.parse(process.argv);1516// Try the following:17// node custom-version -v18// node custom-version --VERSION17// node custom-version -v18// node custom-version --VERSION
modified:examples/defaultCommand.js+5 added-7 removed
modified:examples/description+6 added
14 unmodified lines
1516program.parse(process.argv);1718if (!program.args.length) program.help();1920// Try the following on macOS or Linux:21// ./description -h22//23// Try the following:24// node description -h
modified:examples/hook.js+6 added-6 removed
46 unmodified lines
47// Some of the hooks or actions are async, so call parseAsync rather than parse.48program.parseAsync().then(() => {});4950// Try the following:51// node hook.js hello52// node hook.js --profile hello53// node hook.js --trace hello --example54// node hook.js delay55// node hook.js --trace delay 5 --message bye56// node hook.js --profile delay51// node hook.js hello52// node hook.js --profile hello53// node hook.js --trace hello --example54// node hook.js delay55// node hook.js --trace delay 5 --message bye56// node hook.js --profile delay
modified:examples/nestedCommands.js+4 added-7 removed
6 unmodified lines
7// Commander supports nested subcommands.8// .command() can add a subcommand with an action handler or an executable.9// .addCommand() adds a prepared command with an action handler.1011// Example output:12//13// $ node nestedCommands.js brew tea14// brew tea15// $ node nestedCommands.js heat jug16// heat jug1711// Add nested commands using `.command()`.12const brew = program.command('brew');13brew14 .command('tea')
24 unmodified lines
39}40program.addCommand(makeHeatCommand());4142program.parse(process.argv);4344// Try the following:45// node nestedCommands.js brew tea46// node nestedCommands.js heat jug
modified:examples/options-env.js+11 added-11 removed
20 unmodified lines
21program.parse();22console.log(program.opts());2324// Try the following:25// node options-env.js --help25// node options-env.js --help26//27// node options-env.js28// PORT=9001 node options-env.js29// PORT=9001 node options-env.js --port 12327// node options-env.js28// PORT=9001 node options-env.js29// PORT=9001 node options-env.js --port 12330//31// COLOUR= node options-env.js32// COLOUR= node options-env.js --no-colour33// NO_COLOUR= node options-env.js34// NO_COLOUR= node options-env.js --colour31// COLOUR= node options-env.js32// COLOUR= node options-env.js --no-colour33// NO_COLOUR= node options-env.js34// NO_COLOUR= node options-env.js --colour35//36// SIZE=small node options-env.js37// SIZE=enormous node options-env.js38// SIZE=enormous node options-env.js --size=large36// SIZE=small node options-env.js37// SIZE=enormous node options-env.js38// SIZE=enormous node options-env.js --size=large
modified:examples/options-extra.js+3 added-3 removed
16 unmodified lines
1718console.log('Options: ', program.opts());1920// Try the following:21// node options-extra.js --help22// node options-extra.js --drink huge23// PORT=80 node options-extra.js21// node options-extra.js --help22// node options-extra.js --drink huge23// PORT=80 node options-extra.js
modified:examples/options-required.js+6 added-5 removed
2 unmodified lines
3// This is used as an example in the README for:4// Required option5// You may specify a required (mandatory) option using `.requiredOption`.6// The option must be specified on the command line, or by having a default value.7//8// Example output pretending command called pizza (or try directly with `node options-required.js`)9//10// $ pizza11// error: required option '-c, --cheese <type>' not specified78// const commander = require('commander'); // (normal include)9const commander = require('../'); // include commander in git clone of commander repo10const program = new commander.Command();
1 unmodified line
12program13 .requiredOption('-c, --cheese <type>', 'pizza must have cheese');1415program.parse();1617console.log(`Cheese type: ${program.opts().cheese}`);1819// Try the following:20// node options-required.js21// node options-required.js --cheese blue
modified:examples/options-variadic.js+3 added-3 removed
14 unmodified lines
15console.log('Options: ', program.opts());16console.log('Remaining arguments: ', program.args);1718// Try the following:19// node options-variadic.js -n 1 2 3 --letter a b c20// node options-variadic.js --letter=A -n80 operand21// node options-variadic.js --letter -n 1 -n 2 3 -- operand19// node options-variadic.js -n 1 2 3 --letter a b c20// node options-variadic.js --letter=A -n80 operand21// node options-variadic.js --letter -n 1 -n 2 3 -- operand
modified:examples/pass-through-options.js-1 removed
15 unmodified lines
1617program.parse();1819// Try the following:20//20// node pass-through-options.js git status21// node pass-through-options.js git --version22// node pass-through-options.js --dry-run git checkout -b new-branch23// node pass-through-options.js git push --dry-run
modified:examples/pizza+8 added
15 unmodified lines
16console.log('you ordered a pizza with:');17if (options.peppers) console.log(' - peppers');18const cheese = !options.cheese ? 'no' : options.cheese;19console.log(' - %s cheese', cheese);2021// Try the following on macOS or Linux:22// ./pizza --help 23//24// Try the following:25// ./pizza --help 26// node pizza --peppers --cheese=blue27// node pizza --no-cheese
modified:examples/pm+15 added-14 removed
2 unmodified lines
3// const { Command } = require('commander'); // (normal include)4const { Command } = require('../'); // include commander in git clone of commander repo5const program = new Command();67// Example of subcommands which are implemented as stand-alone executable files.8//9// When `.command()` is invoked with a description argument,10// this tells Commander that you're going to use a stand-alone executable for the subcommand.11//12// Only `install` and `list` are implemented, see pm-install and pm-list.js1314program15 .version('0.0.1')16 .description('Fake package manager')17 .command('install [name]', 'install one or more packages').alias('i')
2 unmodified lines
20 .command('list', 'list packages installed', { isDefault: true });2122program.parse(process.argv);2317// here .command() is invoked with a description,18// and no .action(callback) calls to handle sub-commands.19// this tells commander that you're going to use separate20// executables for sub-commands, much like git(1) and other21// popular tools.2223// here only ./pm-install(1) and ./pm-list(1) are implemented, however you24// would define ./pm-search(1) etc.2524// Try the following on macOS or Linux:25// ./examples/pm26//27// Try the following:27// ./examples/pm28// ./examples/pm help install29// ./examples/pm install -h30// ./examples/pm install foo bar baz31// ./examples/pm install foo bar baz --force28// node pm29// node pm help install30// node pm install -h31// node pm install foo bar baz32// node pm install foo bar baz --force
modified:examples/positional-options.js-1 removed
18 unmodified lines
1920program.parse();2122// Try the following:23//23// node positional-options.js upload test.js24// node positional-options.js -p upload test.js25// node positional-options.js upload -p 8080 test.js26// node positional-options.js -p upload -p 8080 test.js
modified:examples/thank.js+3 added-3 removed
19 unmodified lines
2021program.parse();2223// Try the following:24// node thank.js John25// node thank.js Doe --title Mr26// node thank.js --debug Doe --title Mr24// node thank.js John25// node thank.js Doe --title Mr26// node thank.js --debug Doe --title Mr