Skip to content
Myr

Add getOptionValueSourceWithGlobals for completeness. (#1832)

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 0ae5b2f · Browse files · 4 files+132 added−53 removed
This commit

State

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

Diff stats

4 files+132 added−53 removed

  • tests:+104 added−52 removed
  • other:+28 added−1 removed

4 files+132 added−53 removed

modified:lib/command.js+19 added
813 unmodified lines
814 return this._optionValueSources[key];815 }816817 /**818 * Get source of option value. See also .optsWithGlobals().819 * Expected values are default | config | env | cli | implied820 *821 * @param {string} key822 * @return {string}823 */824825 getOptionValueSourceWithGlobals(key) {826 // global overwrites local, like optsWithGlobals827 let source;828 getCommandAndParents(this).forEach((cmd) => {829 if (cmd.getOptionValueSource(key) !== undefined) {830 source = cmd.getOptionValueSource(key);831 }832 });833 return source;834 }835836 /**837 * Get user arguments from implied or explicit arguments.838 * Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.839 *840 * @api private
1339 unmodified lines
modified:tests/options.optsWithGlobals.test.js+104 added-52 removed
modified:typings/index.d.ts+6 added-1 removed
598 unmodified lines
599 */600 setOptionValueWithSource(key: string, value: unknown, source: OptionValueSource): this;601602 /**603 * Retrieve option value source.603 * Get source of option value.604 */605 getOptionValueSource(key: string): OptionValueSource | undefined;606607 /**608 * Get source of option value. See also .optsWithGlobals().609 */610 getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined;611612 /**613 * Alter parsing of short flags with optional values.614 *615 * @example616 * ```
275 unmodified lines
modified:typings/index.test-d.ts+3 added
172 unmodified lines
173174// getOptionValueSource175expectType<commander.OptionValueSource | undefined>(program.getOptionValueSource('example'));176177// getOptionValueSourceWithGlobals178expectType<commander.OptionValueSource | undefined>(program.getOptionValueSourceWithGlobals('example'));179180// combineFlagAndOptionalValue181expectType<commander.Command>(program.combineFlagAndOptionalValue());182expectType<commander.Command>(program.combineFlagAndOptionalValue(false));183
297 unmodified lines