Give optional boolean parameters appropriate name, and coerce value to boolean (#1384)
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 7a0baab · Browse files · 2 files·+24 added−25 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+24 added−25 removed
- other:+24 added−25 removed
Provenance
- Commit
df5d679- Tree
d0aa762- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
7a0baab
2 files changed+24 added−25 removed
modified:typings/index.d.ts+6 added-7 removed
48 unmodified lines49 50 /**51 * Whether the option is mandatory and must have a value after parsing.52 */53- makeOptionMandatory(value?: boolean): this;53+ makeOptionMandatory(mandatory?: boolean): this;54 55 /**56 * Hide option in help.57 */58- hideHelp(value?: boolean): this;58+ hideHelp(hide?: boolean): this;59 60 /**61 * Validation of option argument failed.62 * Intended for use from custom argument processing functions.280 unmodified lines343 * or store separately (specify false). In both cases the option values can be accessed using .opts().344 *345 * @returns `this` command for chaining346 */347- storeOptionsAsProperties(value?: boolean): this;347+ storeOptionsAsProperties(storeAsProperties?: boolean): this;348 349 /**350 * Whether to pass command to action handler,351 * or just the options (specify false).352 *353 * @returns `this` command for chaining354 */355- passCommandToAction(value?: boolean): this;355+ passCommandToAction(passCommand?: boolean): this;356 357 /**358 * Alter parsing of short flags with optional values.359 *3 unmodified lines363 * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`364 *365 * @returns `this` command for chaining366 */367- combineFlagAndOptionalValue(arg?: boolean): this;367+ combineFlagAndOptionalValue(combine?: boolean): this;368 369 /**370 * Allow unknown options on the command line.371 *372- * @param [arg] if `true` or omitted, no error will be thrown for unknown options.372 * @returns `this` command for chaining373 */375- allowUnknownOption(arg?: boolean): this;374+ allowUnknownOption(allowUnknown?: boolean): this;375 376 /**377 * Parse `argv`, setting options and invoking commands when defined.378 *184 unmodified linesmodified:index.js+18 added-18 removed
399 unmodified lines400 401 /**402 * Whether the option is mandatory and must have a value after parsing.403 *404- * @param {boolean} [value]404+ * @param {boolean} [mandatory]405 * @return {Option}406 */407 408- makeOptionMandatory(value) {409- this.mandatory = (value === undefined) || value;408+ makeOptionMandatory(mandatory) {409+ this.mandatory = (mandatory === undefined) || !!mandatory;410 return this;411 };412 413 /**414 * Hide option in help.415 *416- * @param {boolean} [value]416+ * @param {boolean} [hide]417 * @return {Option}418 */419 420- hideHelp(value) {421- this.hidden = (value === undefined) || value;420+ hideHelp(hide) {421+ this.hidden = (hide === undefined) || !!hide;422 return this;423 };424 425 /**679 unmodified lines1105 * // for `.option('-f,--flag [value]'):1106 * .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour1107 * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`1108 *1109- * @param {Boolean} [arg] - if `true` or omitted, an optional value can be specified directly after the flag.1109+ * @param {Boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.1110 */1111- combineFlagAndOptionalValue(arg) {1112- this._combineFlagAndOptionalValue = (arg === undefined) || arg;1111+ combineFlagAndOptionalValue(combine) {1112+ this._combineFlagAndOptionalValue = (combine === undefined) || !!combine;1113 return this;1114 };1115 1116 /**1117 * Allow unknown options on the command line.1118 *1119- * @param {Boolean} [arg] - if `true` or omitted, no error will be thrown1119+ * @param {Boolean} [allowUnknown] - if `true` or omitted, no error will be thrown1120 * for unknown options.1121 */1122- allowUnknownOption(arg) {1123- this._allowUnknownOption = (arg === undefined) || arg;1122+ allowUnknownOption(allowUnknown) {1123+ this._allowUnknownOption = (allowUnknown === undefined) || !!allowUnknown;1124 return this;1125 };1126 1127 /**1128 * Whether to store option values as properties on command object,1129 * or store separately (specify false). In both cases the option values can be accessed using .opts().1130 *1131- * @param {boolean} value1131+ * @param {boolean} storeAsProperties1132 * @return {Command} `this` command for chaining1133 */1134 1135- storeOptionsAsProperties(value) {1135+ storeOptionsAsProperties(storeAsProperties) {1136 this._storeOptionsAsPropertiesCalled = true;1137- this._storeOptionsAsProperties = (value === undefined) || value;1137+ this._storeOptionsAsProperties = (storeAsProperties === undefined) || !!storeAsProperties;1138 if (this.options.length) {1139 throw new Error('call .storeOptionsAsProperties() before adding options');1140 }1141 return this;2 unmodified lines1144 /**1145 * Whether to pass command to action handler,1146 * or just the options (specify false).1147 *1148- * @param {boolean} value1148+ * @param {boolean} passCommand1149 * @return {Command} `this` command for chaining1150 */1151 1152- passCommandToAction(value) {1153- this._passCommandToAction = (value === undefined) || value;1152+ passCommandToAction(passCommand) {1153+ this._passCommandToAction = (passCommand === undefined) || !!passCommand;1154 return this;1155 };1156 1157 /**959 unmodified lines