Skip to content

Commit

Permalink
Change option defaultValues to allow any type, not just string or boo…
Browse files Browse the repository at this point in the history
…lean
  • Loading branch information
carsonreinke committed Jul 21, 2020
1 parent ab7864a commit 1ff7d6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions typings/commander-tests.ts
Expand Up @@ -81,6 +81,7 @@ const optionThis1: commander.Command = program.option('-a,--alpha');
const optionThis2: commander.Command = program.option('-p, --peppers', 'Add peppers');
const optionThis3: commander.Command = program.option('-s, --string [value]', 'default string', 'value');
const optionThis4: commander.Command = program.option('-b, --boolean', 'default boolean', false);
const optionThis5: commander.Command = program.option('-o, --object [value]', 'default object', {key: 'value'});

// example coercion functions from README

Expand All @@ -104,13 +105,13 @@ function commaSeparatedList(value: string, dummyPrevious: string[]): string[] {
return value.split(',');
}

const optionThis5: commander.Command = program.option('-f, --float <number>', 'float argument', parseFloat);
const optionThis6: commander.Command = program.option('-f, --float <number>', 'float argument', parseFloat, 3.2);
const optionThis7: commander.Command = program.option('-i, --integer <number>', 'integer argument', myParseInt);
const optionThis8: commander.Command = program.option('-i, --integer <number>', 'integer argument', myParseInt, 5);
const optionThis9: commander.Command = program.option('-v, --verbose', 'verbosity that can be increased', increaseVerbosity, 0);
const optionThis10: commander.Command = program.option('-c, --collect <value>', 'repeatable value', collect, []);
const optionThis11: commander.Command = program.option('-l, --list <items>', 'comma separated list', commaSeparatedList);
const optionThis6: commander.Command = program.option('-f, --float <number>', 'float argument', parseFloat);
const optionThis7: commander.Command = program.option('-f, --float <number>', 'float argument', parseFloat, 3.2);
const optionThis8: commander.Command = program.option('-i, --integer <number>', 'integer argument', myParseInt);
const optionThis9: commander.Command = program.option('-i, --integer <number>', 'integer argument', myParseInt, 5);
const optionThis10: commander.Command = program.option('-v, --verbose', 'verbosity that can be increased', increaseVerbosity, 0);
const optionThis11: commander.Command = program.option('-c, --collect <value>', 'repeatable value', collect, []);
const optionThis12: commander.Command = program.option('-l, --list <items>', 'comma separated list', commaSeparatedList);

// requiredOption, same tests as option
const requiredOptionThis1: commander.Command = program.requiredOption('-a,--alpha');
Expand Down
8 changes: 4 additions & 4 deletions typings/index.d.ts
Expand Up @@ -171,8 +171,8 @@ declare namespace commander {
*
* @returns `this` command for chaining
*/
option(flags: string, description?: string, defaultValue?: string | boolean): this;
option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
option(flags: string, description?: string, defaultValue?: any): this;
option(flags: string, description: string, regexp: RegExp, defaultValue?: any): this;
option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;

/**
Expand All @@ -181,8 +181,8 @@ declare namespace commander {
*
* The `flags` string should contain both the short and long flags, separated by comma, a pipe or space.
*/
requiredOption(flags: string, description?: string, defaultValue?: string | boolean): this;
requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
requiredOption(flags: string, description?: string, defaultValue?: any): this;
requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: any): this;
requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;

/**
Expand Down

0 comments on commit 1ff7d6f

Please sign in to comment.