Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions typings/commander-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ function collect(val: string, memo: string[]) {
memo.push(val);
return memo;
}
/*
Comment thread
shadowspawn marked this conversation as resolved.
Outdated
* Collector without return all so work
Comment thread
UrielCh marked this conversation as resolved.
Outdated
*/
//function collect2(val: string, memo: string[]) {
// memo.push(val);
//}

function increaseVerbosity(v: any, total: number) {
return total + 1;
Expand All @@ -51,6 +57,7 @@ program
.option('-l, --list <items>', 'A list', list)
.option('-o, --optional [value]', 'An optional value')
.option('-c, --collect [value]', 'A repeatable value', collect, [])
// .option('--collect2 [value]', 'A repeatable value void return', collect2, [])
.option('-v, --verbose', 'A value that can be increased', increaseVerbosity, 0)
.parse(process.argv);

Expand Down
16 changes: 6 additions & 10 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,20 @@ declare namespace commander {
*
* // optional argument
* program.option('-c, --cheese [type]', 'add cheese [marble]');
*
* @param {string} flags
* @param {string} [description]
* @param {((arg1: any, arg2: any) => void) | RegExp} [fn] function or default
* @param {*} [defaultValue]
* @returns {Command} for chaining
*/
option(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command;
option(flags: string, description?: string, defaultValue?: any): Command;
option(flags: string, description?: string, defaultValue?: string): Command;
Comment thread
UrielCh marked this conversation as resolved.
Outdated
option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): Command;
option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): Command;

/**
* Define a required option, which must have a value after parsing. This usually means
* the option must be specified on the command line. (Otherwise the same as .option().)
*
* The `flags` string should contain both the short and long flags, separated by comma, a pipe or space.
*/
requiredOption(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command;
requiredOption(flags: string, description?: string, defaultValue?: any): Command;
requiredOption(flags: string, description?: string, defaultValue?: string): Command;
requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): Command;
requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): Command;

/**
* Allow unknown options on the command line.
Expand Down