Use revised terminology (#1362)
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 e56fba2 · Browse files · 3 files·+49 added−45 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+49 added−45 removed
- other:+49 added−45 removed
Provenance
- Commit
2f4cd3d- Tree
cc24cc0- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
e56fba2
3 files changed+49 added−45 removed
added:examples/options-boolean-or-value.js+27 added
123456789101112131415161718192021222324252627#!/usr/bin/env node
// This is used as an example in the README for:// Other option types, flag|value// You can specify an option which functions as a flag but may also take a value (declared using square brackets).//// Example output pretending command called pizza-options (or try directly with `node options-flag-or-value.js`)//// $ pizza-options// no cheese// $ pizza-options --cheese// add cheese// $ pizza-options --cheese mozzarella// add cheese type mozzarella
// const commander = require('commander'); // (normal include)const commander = require('../'); // include commander in git clone of commander repoconst program = new commander.Command();
program .option('-c, --cheese [type]', 'Add cheese with optional type');
program.parse(process.argv);
if (program.cheese === undefined) console.log('no cheese');else if (program.cheese === true) console.log('add cheese');else console.log(`add cheese type ${program.cheese}`);deleted:examples/options-flag-or-value.js-27 removed
123456789101112131415161718192021222324252627#!/usr/bin/env node
// This is used as an example in the README for:// Other option types, flag|value// You can specify an option which functions as a flag but may also take a value (declared using square brackets).//// Example output pretending command called pizza-options (or try directly with `node options-flag-or-value.js`)//// $ pizza-options// no cheese// $ pizza-options --cheese// add cheese// $ pizza-options --cheese mozzarella// add cheese type mozzarella
// const commander = require('commander'); // (normal include)const commander = require('../'); // include commander in git clone of commander repoconst program = new commander.Command();
program .option('-c, --cheese [type]', 'Add cheese with optional type');
program.parse(process.argv);
if (program.cheese === undefined) console.log('no cheese');else if (program.cheese === true) console.log('add cheese');else console.log(`add cheese type ${program.cheese}`);modified:Readme.md+22 added-18 removed
13 unmodified lines14 - [Declaring _program_ variable](#declaring-program-variable)15 - [Options](#options)16 - [Common option types, boolean and value](#common-option-types-boolean-and-value)17 - [Default option value](#default-option-value)18- - [Other option types, negatable boolean and flag|value](#other-option-types-negatable-boolean-and-flagvalue)18+ - [Other option types, negatable boolean and boolean|value](#other-option-types-negatable-boolean-and-booleanvalue)19 - [Custom option processing](#custom-option-processing)20 - [Required option](#required-option)21 - [Variadic option](#variadic-option)22 - [Version option](#version-option)58 unmodified lines81 Multiple short flags may optionally be combined in a single argument following the dash: boolean flags, followed by a single option taking a value (possibly followed by the value).82 For example `-a -b -p 80` may be written as `-ab -p80` or even `-abp80`.83 84 You can use `--` to indicate the end of the options, and any remaining arguments will be used without being interpreted.85-This is particularly useful for passing options through to another86-command, like: `do -- git --version`.85 88-Options on the command line are not positional, and can be specified before or after other command arguments.86+Options on the command line are not positional, and can be specified before or after other arguments.87 88 ### Common option types, boolean and value89 92-The two most used option types are a boolean flag, and an option which takes a value (declared using angle brackets). Both are `undefined` unless specified on command line.90+The two most used option types are a boolean option, and an option which takes its value91+from the following argument (declared with angle brackets like `--expect <value>`). Both are `undefined` unless specified on command line. 92 93 Example file: [options-common.js](./examples/options-common.js)94 95 ```js49 unmodified lines145 $ pizza-options --cheese stilton146 cheese: stilton147 ```148 150-### Other option types, negatable boolean and flag|value149+### Other option types, negatable boolean and boolean|value150 152-You can specify a boolean option long name with a leading `no-` to set the option value to false when used.151+You can define a boolean option long name with a leading `no-` to set the option value to false when used.152 Defined alone this also makes the option true by default.153 154 If you define `--foo` first, adding `--no-foo` does not change the default value from what it would156-otherwise be. You can specify a default boolean value for a boolean flag and it can be overridden on command line.155+otherwise be. You can specify a default boolean value for a boolean option and it can be overridden on command line.156 157 Example file: [options-negatable.js](./examples/options-negatable.js)158 159 ```js18 unmodified lines178 $ pizza-options --no-sauce --no-cheese179 You ordered a pizza with no sauce and no cheese180 ```181 183-You can specify an option which functions as a flag but may also take a value (declared using square brackets).182+You can specify an option which may be used as a boolean option but may optionally take an option-argument183+(declared with square brackets like `--optional [value]`).184 185-Example file: [options-flag-or-value.js](./examples/options-flag-or-value.js)185+Example file: [options-boolean-or-value.js](./examples/options-boolean-or-value.js)186 187 ```js188 program189 .option('-c, --cheese [type]', 'Add cheese with optional type');17 unmodified lines207 For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).208 209 ### Custom option processing210 211-You may specify a function to do custom processing of option values. The callback function receives two parameters, the user specified value and the212-previous value for the option. It returns the new value for the option.211+You may specify a function to do custom processing of option-arguments. The callback function receives two parameters,212+the user specified option-argument and the previous value for the option. It returns the new value for the option.213 214-This allows you to coerce the option value to the desired type, or accumulate values, or do entirely custom processing.214+This allows you to coerce the option-argument to the desired type, or accumulate values, or do entirely custom processing.215 216-You can optionally specify the default/starting value for the option after the function.216+You can optionally specify the default/starting value for the option after the function parameter.217 218 Example file: [options-custom-processing.js](./examples/options-custom-processing.js)219 220 ```js64 unmodified lines285 286 ### Variadic option287 288 You may make an option variadic by appending `...` to the value placeholder when declaring the option. On the command line you289-can then specify multiple option arguments, and the parsed option value will be an array. The extra arguments289+can then specify multiple option-arguments, and the parsed option value will be an array. The extra arguments290 are read until the first argument starting with a dash. The special argument `--` stops option processing entirely. If a value291 is specified in the same argument as the option then no further values are read.292 293 Example file: [options-variadic.js](./examples/options-variadic.js)46 unmodified lines340 ## Commands341 342 You can specify (sub)commands using `.command()` or `.addCommand()`. There are two ways these can be implemented: using an action handler attached to the command, or as a stand-alone executable file (described in more detail later). The subcommands may be nested ([example](./examples/nestedCommands.js)).343 344-In the first parameter to `.command()` you specify the command name and any command arguments. The arguments may be `<required>` or `[optional]`, and the last argument may also be `variadic...`.344+In the first parameter to `.command()` you specify the command name and any command-arguments. The arguments may be `<required>` or `[optional]`, and the last argument may also be `variadic...`.345 346 You can use `.addCommand()` to add an already configured subcommand to the program.347 348 For example:19 unmodified lines368 program369 .addCommand(build.makeBuildCommand());370 ```371 372-Configuration options can be passed with the call to `.command()` and `.addCommand()`. Specifying `true` for `opts.hidden` will remove the command from the generated help output. Specifying `true` for `opts.isDefault` will run the subcommand if no other subcommand is specified ([example](./examples/defaultCommand.js)).372+Configuration options can be passed with the call to `.command()` and `.addCommand()`. Specifying `hidden: true` will 373+remove the command from the generated help output. Specifying `isDefault: true` will run the subcommand if no other374+subcommand is specified ([example](./examples/defaultCommand.js)).375 376 ### Specify the argument syntax377 376-You use `.arguments` to specify the arguments for the top-level command, and for subcommands they are usually included in the `.command` call. Angled brackets (e.g. `<required>`) indicate required input. Square brackets (e.g. `[optional]`) indicate optional input.378+You use `.arguments` to specify the expected command-arguments for the top-level command, and for subcommands they are usually379+included in the `.command` call. Angled brackets (e.g. `<required>`) indicate required command-arguments.380+Square brackets (e.g. `[optional]`) indicate optional command-arguments.381 You can optionally describe the arguments in the help by supplying a hash as second parameter to `.description()`.382 383 Example file: [env](./examples/env)384 407 unmodified lines