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

Fix option value source type #1963

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -780,15 +780,15 @@ Expecting one of '${allowedValues.join("', '")}'`);
*/

setOptionValue(key, value) {
return this.setOptionValueWithSource(key, value, undefined);
return this.setOptionValueWithSource(key, value);
}

/**
* 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/implied
* @param {string} [source] - expected values are default/config/env/cli/implied
* @return {Command} `this` command for chaining
*/

Expand All @@ -807,7 +807,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
* Expected values are default | config | env | cli | implied
*
* @param {string} key
* @return {string}
* @return {string | undefined}
*/

getOptionValueSource(key) {
Expand All @@ -819,7 +819,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
* Expected values are default | config | env | cli | implied
*
* @param {string} key
* @return {string}
* @return {string | undefined}
*/

getOptionValueSourceWithGlobals(key) {
Expand Down
6 changes: 3 additions & 3 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,17 +595,17 @@ export class Command {
/**
* Store option value and where the value came from.
*/
setOptionValueWithSource(key: string, value: unknown, source: OptionValueSource): this;
setOptionValueWithSource(key: string, value: unknown, source?: OptionValueSource | string | undefined): this;

/**
* Get source of option value.
*/
getOptionValueSource(key: string): OptionValueSource | undefined;
getOptionValueSource(key: string): OptionValueSource | string | undefined;

/**
* Get source of option value. See also .optsWithGlobals().
*/
getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined;
getOptionValueSourceWithGlobals(key: string): OptionValueSource | string | undefined;

/**
* Alter parsing of short flags with optional values.
Expand Down
4 changes: 2 additions & 2 deletions typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ expectType<commander.Command>(program.setOptionValue('example', true));
expectType<commander.Command>(program.setOptionValueWithSource('example', [], 'cli'));

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

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

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