Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implied to option value sources #1794

Merged
merged 4 commits into from Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/command.js
Expand Up @@ -37,7 +37,7 @@ class Command extends EventEmitter {
this._scriptPath = null;
this._name = name || '';
this._optionValues = {};
this._optionValueSources = {}; // default < config < env < cli
this._optionValueSources = {}; // default, env, cli etc
this._storeOptionsAsProperties = false;
this._actionHandler = null;
this._executableHandler = false;
Expand Down Expand Up @@ -789,11 +789,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
}

/**
* Store option value and where the value came from.
* Store option value and where the value came from.
*
* @param {string} key
* @param {Object} value
* @param {string} source - expected values are default/config/env/cli
* @param {string} source - expected values are default/config/env/cli/implied
* @return {Command} `this` command for chaining
*/

Expand All @@ -805,7 +805,7 @@ Expecting one of '${allowedValues.join("', '")}'`);

/**
* Get source of option value.
* Expected values are default | config | env | cli
* Expected values are default | config | env | cli | implied
*
* @param {string} key
* @return {string}
Expand Down
4 changes: 3 additions & 1 deletion lib/option.js
Expand Up @@ -105,7 +105,9 @@ class Option {

/**
* Set environment variable to check for option value.
* Priority order of option values is default < env < cli
*
* An environment variable is only used if when processed the current option value is
* undefined, or the source of the current value is 'default' or 'config' or 'env'.
*
* @param {string} name
* @return {Option}
Expand Down
8 changes: 5 additions & 3 deletions typings/index.d.ts
Expand Up @@ -144,7 +144,9 @@ export class Option {

/**
* Set environment variable to check for option value.
* Priority order of option values is default < env < cli
*
* An environment variables is only used if when processed the current option value is
* undefined, or the source of the current value is 'default' or 'config' or 'env'.
*/
env(name: string): this;

Expand Down Expand Up @@ -266,7 +268,7 @@ export interface OutputConfiguration {

export type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll';
export type HookEvent = 'preSubcommand' | 'preAction' | 'postAction';
export type OptionValueSource = 'default' | 'env' | 'config' | 'cli';
export type OptionValueSource = 'default' | 'config' | 'env' | 'cli' | 'implied';

export interface OptionValues {
[key: string]: any;
Expand Down Expand Up @@ -595,7 +597,7 @@ export class Command {
/**
* Retrieve option value source.
*/
getOptionValueSource(key: string): OptionValueSource;
getOptionValueSource(key: string): OptionValueSource | undefined;

/**
* Alter parsing of short flags with optional values.
Expand Down
2 changes: 1 addition & 1 deletion typings/index.test-d.ts
Expand Up @@ -172,7 +172,7 @@ expectType<commander.Command>(program.setOptionValue('example', true));
expectType<commander.Command>(program.setOptionValueWithSource('example', [], 'cli'));

// getOptionValueSource
expectType<commander.OptionValueSource>(program.getOptionValueSource('example'));
expectType<commander.OptionValueSource | undefined>(program.getOptionValueSource('example'));

// combineFlagAndOptionalValue
expectType<commander.Command>(program.combineFlagAndOptionalValue());
Expand Down