Skip to content
Myr

Add implied to option value sources (#1794)

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

* TypeScript: add implied to OptionValueSource * Add implied to JSDoc and TSDoc. Mention config in env priority. * TypeScript: add undefined to return type of getOptionValueSource * Reword env description so not priority ordering as such. More accurately describe behaviour.

authored by John Gee · committed by GitHub · parent 84d9201 · Browse files · 4 files+13 added−9 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+13 added−9 removed

  • other:+13 added−9 removed

4 files+13 added−9 removed

modified:lib/command.js+4 added-4 removed
35 unmodified lines
36 this.processedArgs = []; // like .args but after custom processing and collecting variadic37 this._scriptPath = null;38 this._name = name || '';39 this._optionValues = {};40 this._optionValueSources = {}; // default < config < env < cli40 this._optionValueSources = {}; // default, env, cli etc41 this._storeOptionsAsProperties = false;42 this._actionHandler = null;43 this._executableHandler = false;44 this._executableFile = null; // custom name for executable
738 unmodified lines
783 return this.setOptionValueWithSource(key, value, undefined);784 }785786 /**787 * Store option value and where the value came from.787 * Store option value and where the value came from.788 *789 * @param {string} key790 * @param {Object} value791 * @param {string} source - expected values are default/config/env/cli791 * @param {string} source - expected values are default/config/env/cli/implied792 * @return {Command} `this` command for chaining793 */794795 setOptionValueWithSource(key, value, source) {
7 unmodified lines
803 }804805 /**806 * Get source of option value.807 * Expected values are default | config | env | cli807 * Expected values are default | config | env | cli | implied808 *809 * @param {string} key810 * @return {string}811 */
1349 unmodified lines
modified:lib/option.js+3 added-1 removed
103 unmodified lines
104 }105106 /**107 * Set environment variable to check for option value.108 * Priority order of option values is default < env < cli108 *109 * An environment variable is only used if when processed the current option value is110 * undefined, or the source of the current value is 'default' or 'config' or 'env'.111 *112 * @param {string} name113 * @return {Option}114 */115
211 unmodified lines
modified:typings/index.d.ts+5 added-3 removed
142 unmodified lines
143 implies(optionValues: OptionValues): this;144145 /**146 * Set environment variable to check for option value.147 * Priority order of option values is default < env < cli147 *148 * An environment variables is only used if when processed the current option value is149 * undefined, or the source of the current value is 'default' or 'config' or 'env'.150 */151 env(name: string): this;152153 /**
113 unmodified lines
267}268269export type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll';270export type HookEvent = 'preSubcommand' | 'preAction' | 'postAction';269export type OptionValueSource = 'default' | 'env' | 'config' | 'cli';271export type OptionValueSource = 'default' | 'config' | 'env' | 'cli' | 'implied';272273export interface OptionValues {274 [key: string]: any;275}
320 unmodified lines
596597 /**598 * Retrieve option value source.599 */598 getOptionValueSource(key: string): OptionValueSource;600 getOptionValueSource(key: string): OptionValueSource | undefined;601602 /**603 * Alter parsing of short flags with optional values.604 *
277 unmodified lines
modified:typings/index.test-d.ts+1 added-1 removed
170 unmodified lines
171// setOptionValueWithSource172expectType<commander.Command>(program.setOptionValueWithSource('example', [], 'cli'));173174// getOptionValueSource175expectType<commander.OptionValueSource>(program.getOptionValueSource('example'));175expectType<commander.OptionValueSource | undefined>(program.getOptionValueSource('example'));176177// combineFlagAndOptionalValue178expectType<commander.Command>(program.combineFlagAndOptionalValue());179expectType<commander.Command>(program.combineFlagAndOptionalValue(false));
295 unmodified lines