Rework option inline doc (#2009)
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 c7d39ca · Browse files · 2 files·+27 added−79 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+27 added−79 removed
- other:+27 added−79 removed
Provenance
- Commit
e85e05a- Tree
8db45ca- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
c7d39ca
2 files changed+27 added−79 removed
modified:lib/command.js+15 added-43 removed
630 unmodified lines631 return this.addOption(option);632 }633 634 /**635- * Define option with `flags`, `description` and optional636- * coercion `fn`.635+ * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.636 *638- * The `flags` string contains the short and/or long flags,639- * separated by comma, a pipe or space. The following are all valid640- * all will output this way when `--help` is used.637+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required638+ * option-argument is indicated by `<>` and an optional option-argument by `[]`.639 *642- * "-p, --pepper"643- * "-p|--pepper"644- * "-p --pepper"640+ * See the README for more details, and see also addOption() and requiredOption().641 *642 * @example647- * // simple boolean defaulting to undefined648- * program.option('-p, --pepper', 'add pepper');643+ * program644+ * .option('-p, --pepper', 'add pepper')645+ * .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument646+ * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default647+ * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function648 *650- * program.pepper651- * // => undefined652- *653- * --pepper654- * program.pepper655- * // => true656- *657- * // simple boolean defaulting to true (unless non-negated option is also defined)658- * program.option('-C, --no-cheese', 'remove cheese');659- *660- * program.cheese661- * // => true662- *663- * --no-cheese664- * program.cheese665- * // => false666- *667- * // required argument668- * program.option('-C, --chdir <path>', 'change the working directory');669- *670- * --chdir /tmp671- * program.chdir672- * // => "/tmp"673- *674- * // optional argument675- * program.option('-c, --cheese [type]', 'add cheese [marble]');676- *649 * @param {string} flags650 * @param {string} [description]679- * @param {Function|*} [fn] - custom option processing function or default value651+ * @param {Function|*} [parseArg] - custom option processing function or default value652 * @param {*} [defaultValue]653 * @return {Command} `this` command for chaining654 */655 684- option(flags, description, fn, defaultValue) {685- return this._optionEx({}, flags, description, fn, defaultValue);656+ option(flags, description, parseArg, defaultValue) {657+ return this._optionEx({}, flags, description, parseArg, defaultValue);658 }659 660 /**661 * Add a required option which must have a value after parsing. This usually means2 unmodified lines664 * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.665 *666 * @param {string} flags667 * @param {string} [description]696- * @param {Function|*} [fn] - custom option processing function or default value668+ * @param {Function|*} [parseArg] - custom option processing function or default value669 * @param {*} [defaultValue]670 * @return {Command} `this` command for chaining671 */672 701- requiredOption(flags, description, fn, defaultValue) {702- return this._optionEx({ mandatory: true }, flags, description, fn, defaultValue);673+ requiredOption(flags, description, parseArg, defaultValue) {674+ return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);675 }676 677 /**678 * Alter parsing of short flags with optional values.1502 unmodified linesmodified:typings/index.d.ts+12 added-36 removed
508 unmodified lines509 */510 action(fn: (...args: any[]) => void | Promise<void>): this;511 512 /**513- * Define option with `flags`, `description` and optional514- * coercion `fn`.513+ * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.514 *516- * The `flags` string contains the short and/or long flags,517- * separated by comma, a pipe or space. The following are all valid518- * all will output this way when `--help` is used.515+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required516+ * option-argument is indicated by `<>` and an optional option-argument by `[]`.517 *520- * "-p, --pepper"521- * "-p|--pepper"522- * "-p --pepper"518+ * See the README for more details, and see also addOption() and requiredOption().519 *520 * @example525- * ```526- * // simple boolean defaulting to false527- * program.option('-p, --pepper', 'add pepper');521 *529- * --pepper530- * program.pepper531- * // => Boolean532- *533- * // simple boolean defaulting to true534- * program.option('-C, --no-cheese', 'remove cheese');535- *536- * program.cheese537- * // => true538- *539- * --no-cheese540- * program.cheese541- * // => false542- *543- * // required argument544- * program.option('-C, --chdir <path>', 'change the working directory');545- *546- * --chdir /tmp547- * program.chdir548- * // => "/tmp"549- *550- * // optional argument551- * program.option('-c, --cheese [type]', 'add cheese [marble]');522+ * ```js523+ * program524+ * .option('-p, --pepper', 'add pepper')525+ * .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument526+ * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default527+ * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function528 * ```529 *530 * @returns `this` command for chaining531 */532 option(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;557- option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;533+ option<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;534 /** @deprecated since v7, instead use choices or a custom function */535 option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;536 537 /**2 unmodified lines540 *541 * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.542 */543 requiredOption(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;568- requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;544+ requiredOption<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;545 /** @deprecated since v7, instead use choices or a custom function */546 requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;547 548 /**330 unmodified lines