mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Add completion function
This commit is contained in:
@@ -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]");
|
||||
|
||||
Vendored
+8
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user