Merge pull request #6196 from nikeee/yargs-patch

Add completion and command parameter to yargs
This commit is contained in:
Horiuchi_H
2015-10-08 16:14:27 +09:00
2 changed files with 52 additions and 0 deletions
+43
View File
@@ -134,6 +134,49 @@ function Argv$options() {
;
}
function command() {
var argv = yargs
.usage('npm <command>')
.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]");
+9
View File
@@ -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;