Add completion function

This commit is contained in:
Niklas Mollenhauer
2015-10-07 21:20:13 +02:00
parent 2d69a5f8bf
commit 9ccd609dbd
2 changed files with 35 additions and 0 deletions
+27
View File
@@ -150,6 +150,33 @@ function command() {
.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]");
+8
View File
@@ -56,6 +56,11 @@ declare module "yargs" {
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;
check(func: (argv: any, aliases: { [alias: string]: string }) => any): Argv;
@@ -111,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;