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
Provenance
- Commit
2cc3a36- Tree
abba30d- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
43f4743
20 files changed+87 added−78 removed
modified:examples/arguments-extra.js+4 added-4 removed
15 unmodified lines16171819202122232021222315 unmodified lines
program.parse();
// Try the following:// node arguments-extra.js --help// node arguments-extra.js huge// node arguments-extra.js small// node arguments-extra.js medium 30// node arguments-extra.js --help// node arguments-extra.js huge// node arguments-extra.js small// node arguments-extra.js medium 30modified:examples/configure-help.js+1 added-1 removed
19 unmodified lines20212223242419 unmodified lines
program.parse();
// Try the following:// node configure-help.js --help// node configure-help.js --helpmodified:examples/configure-output.js+4 added-4 removed
23 unmodified lines24252627282930312829303123 unmodified lines
program.parse();
// Try the following:// node configure-output.js --version// node configure-output.js --unknown// node configure-output.js --help// node configure-output.js// node configure-output.js --version// node configure-output.js --unknown// node configure-output.js --help// node configure-output.jsmodified:examples/custom-help+1 added-1 removed
16 unmodified lines17 18 program.parse(process.argv);19 20 // Try the following:21-// node custom-help --help21+// node custom-help --helpmodified:examples/custom-help-description+2 added-2 removed
19 unmodified lines20 21 program.parse(process.argv);22 23 // 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 --HELPmodified:examples/custom-help-text.js+3 added-3 removed
26 unmodified lines2728293031323331323326 unmodified lines
program.parse();
// Try the following:// node custom-help-text.js --help// node custom-help-text.js extra --help// node custom-help-text.js// node custom-help-text.js --help// node custom-help-text.js extra --help// node custom-help-text.jsmodified:examples/custom-version+2 added-2 removed
12 unmodified lines13 14 program.parse(process.argv);15 16 // Try the following:17-// node custom-version -v18-// node custom-version --VERSION17+// node custom-version -v18+// node custom-version --VERSIONmodified:examples/defaultCommand.js+5 added-7 removed
3 unmodified lines456789101112131489101116 unmodified lines2829303132333435363 unmodified linesconst commander = require('../'); // include commander in git clone of commander repoconst program = new commander.Command();
// Example program using the command configuration option isDefault to specify the default command.//// $ node defaultCommand.js build// build// $ node defaultCommand.js serve -p 8080// server on port 8080// $ node defaultCommand.js -p 443// server on port 443
program .command('build') .description('build web site for deployment')16 unmodified lines console.log(`server on port ${options.port}`); });
program.parse(process.argv);
// Try the following:// node defaultCommand.js build// node defaultCommand.js serve -p 8080// node defaultCommand.js -p 443modified:examples/description+6 added
14 unmodified lines15 16 program.parse(process.argv);17 18 if (!program.args.length) program.help();19+20+// Try the following on macOS or Linux:21+// ./description -h22+//23+// Try the following:24+// node description -hmodified:examples/hook.js+6 added-6 removed
46 unmodified lines47 // Some of the hooks or actions are async, so call parseAsync rather than parse.48 program.parseAsync().then(() => {});49 50 // 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 delaymodified:examples/nestedCommands.js+4 added-7 removed
6 unmodified lines7 // 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.10 11-// Example output:12-//13-// $ node nestedCommands.js brew tea14-// brew tea15-// $ node nestedCommands.js heat jug16-// heat jug17-11 // Add nested commands using `.command()`.12 const brew = program.command('brew');13 brew14 .command('tea')24 unmodified lines39 }40 program.addCommand(makeHeatCommand());41 42 program.parse(process.argv);43+44+// Try the following:45+// node nestedCommands.js brew tea46+// node nestedCommands.js heat jugmodified:examples/options-env.js+11 added-11 removed
20 unmodified lines21 program.parse();22 console.log(program.opts());23 24 // 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=largemodified:examples/options-extra.js+3 added-3 removed
16 unmodified lines17 18 console.log('Options: ', program.opts());19 20 // 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.jsmodified:examples/options-required.js+6 added-5 removed
2 unmodified lines3 // 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 specified7 8 // const commander = require('commander'); // (normal include)9 const commander = require('../'); // include commander in git clone of commander repo10 const program = new commander.Command();1 unmodified line12 program13 .requiredOption('-c, --cheese <type>', 'pizza must have cheese');14 15 program.parse();16+17+console.log(`Cheese type: ${program.opts().cheese}`);18+19+// Try the following:20+// node options-required.js21+// node options-required.js --cheese bluemodified:examples/options-variadic.js+3 added-3 removed
14 unmodified lines15 console.log('Options: ', program.opts());16 console.log('Remaining arguments: ', program.args);17 18 // 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 -- operandmodified:examples/pass-through-options.js-1 removed
15 unmodified lines16 17 program.parse();18 19 // 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-runmodified:examples/pizza+8 added
15 unmodified lines16 console.log('you ordered a pizza with:');17 if (options.peppers) console.log(' - peppers');18 const cheese = !options.cheese ? 'no' : options.cheese;19 console.log(' - %s cheese', cheese);20+21+// 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-cheesemodified:examples/pm+15 added-14 removed
2 unmodified lines3 // const { Command } = require('commander'); // (normal include)4 const { Command } = require('../'); // include commander in git clone of commander repo5 const program = new Command();6 7+// 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.js13+14 program15 .version('0.0.1')16 .description('Fake package manager')17 .command('install [name]', 'install one or more packages').alias('i')2 unmodified lines20 .command('list', 'list packages installed', { isDefault: true });21 22 program.parse(process.argv);23 17-// 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.22-23-// here only ./pm-install(1) and ./pm-list(1) are implemented, however you24-// would define ./pm-search(1) etc.25-24+// 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 --forcemodified:examples/positional-options.js-1 removed
18 unmodified lines19 20 program.parse();21 22 // 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.jsmodified:examples/thank.js+3 added-3 removed
19 unmodified lines20 21 program.parse();22 23 // 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