diff --git a/yargs/yargs-tests.ts b/yargs/yargs-tests.ts index 10b75382b..f20254990 100644 --- a/yargs/yargs-tests.ts +++ b/yargs/yargs-tests.ts @@ -134,6 +134,49 @@ function Argv$options() { ; } +function command() { + var argv = yargs + .usage('npm ') + .command('install', 'tis a mighty fine package to install') + .command('publish', 'shiver me timbers, should you be sharing all that', yargs => { + argv = yargs.option('f', { + alias: 'force', + description: 'yar, it usually be a bad idea' + }) + .help('help') + .argv; + }) + .help('help') + .argv; +} + +function completion_sync() { + var argv = yargs + .completion('completion', (current, argv) => { + // 'current' is the current command being completed. + // 'argv' is the parsed arguments so far. + // simply return an array of completions. + return [ + 'foo', + 'bar' + ]; + }) + .argv; +} + +function completion_async() { + var argv = yargs + .completion('completion', (current, argv, done) => { + setTimeout(function() { + done([ + 'apple', + 'banana' + ]); + }, 500); + }) + .argv; +} + function Argv$help() { var yargs1 = yargs .usage("$0 -operand1 number -operand2 number -operation [add|subtract]"); diff --git a/yargs/yargs.d.ts b/yargs/yargs.d.ts index 0e42090fc..03b7c05dc 100644 --- a/yargs/yargs.d.ts +++ b/yargs/yargs.d.ts @@ -54,6 +54,12 @@ declare module "yargs" { usage(options?: { [key: string]: Options }): Argv; command(command: string, description: string): Argv; + command(command: string, description: string, fn: (args: Argv) => void): Argv; + + completion(cmd: string, fn?: SyncCompletionFunction): Argv; + completion(cmd: string, description?: string, fn?: SyncCompletionFunction): Argv; + completion(cmd: string, fn?: AsyncCompletionFunction): Argv; + completion(cmd: string, description?: string, fn?: AsyncCompletionFunction): Argv; example(command: string, description: string): Argv; @@ -110,6 +116,9 @@ declare module "yargs" { desc?: any; requiresArg?: any; } + + type SyncCompletionFunction = (current: string, argv: any) => string[]; + type AsyncCompletionFunction = (current: string, argv: any, done: (completion: string[]) => void) => void; } var yargs: yargs.Argv;