Updated to match the command signature as of 4.7.1 (#9693)

This commit is contained in:
Gevik Babakhani
2016-06-19 05:36:36 +02:00
committed by Masahiro Wakame
parent 49164be32a
commit 27896d899d
2 changed files with 42 additions and 27 deletions

View File

@@ -67,14 +67,14 @@ function default_singles() {
.default('x', 10)
.default('y', 10)
.argv
;
;
console.log(argv.x + argv.y);
}
function default_hash() {
var argv = yargs
.default({ x: 10, y: 10 })
.argv
;
;
console.log(argv.x + argv.y);
}
@@ -83,7 +83,7 @@ function boolean_single() {
var argv = yargs
.boolean('v')
.argv
;
;
console.dir(argv.v);
console.dir(argv._);
}
@@ -91,7 +91,7 @@ function boolean_double() {
var argv = yargs
.boolean(['x', 'y', 'z'])
.argv
;
;
console.dir([argv.x, argv.y, argv.z]);
console.dir(argv._);
}
@@ -105,7 +105,7 @@ function line_count() {
.alias('f', 'file')
.describe('f', 'Load a file')
.argv
;
;
}
// Below are tests for individual methods.
@@ -131,13 +131,13 @@ function Argv$options() {
nargs: 3
})
.argv
;
;
var argv2 = yargs
.alias('f', 'file')
.default('f', '/etc/passwd')
.argv
;
;
}
function Argv$global() {
@@ -168,17 +168,17 @@ function Argv$array() {
function Argv$nargs() {
var argv = yargs
.nargs('foo', 12)
.nargs({'bing': 3, 'bang': 2, 'buzz': 4})
.nargs({ 'bing': 3, 'bang': 2, 'buzz': 4 })
}
function Argv$choices() {
// example from documentation
var argv = yargs
.alias('i', 'ingredient')
.describe('i', 'choose your sandwich ingredients')
.choices('i', ['peanut-butter', 'jelly', 'banana', 'pickles'])
.help('help')
.argv
.alias('i', 'ingredient')
.describe('i', 'choose your sandwich ingredients')
.choices('i', ['peanut-butter', 'jelly', 'banana', 'pickles'])
.help('help')
.argv
}
function command() {
@@ -190,8 +190,19 @@ function command() {
alias: 'force',
description: 'yar, it usually be a bad idea'
})
.help('help')
.argv;
.help('help')
.argv;
})
.command("build", "arghh, build it mate", {
tag: {
default: true,
demand: true,
description: "Tag the build, mate!"
},
publish: {
default: false,
description:"Should i publish?"
}
})
.help('help')
.argv;
@@ -214,7 +225,7 @@ function completion_sync() {
function completion_async() {
var argv = yargs
.completion('completion', (current, argv, done) => {
setTimeout(function() {
setTimeout(function () {
done([
'apple',
'banana'
@@ -257,16 +268,16 @@ function Argv$version() {
.version('1.0.0', '--version', 'description');
var argv4 = yargs
.version( function() { return '1.0.0'; }, '--version', 'description');
.version(function () { return '1.0.0'; }, '--version', 'description');
}
function Argv$locale() {
var argv = yargs
.usage('./$0 - follow ye instructions true')
.option('option', {
alias: 'o',
describe: "'tis a mighty fine option",
demand: true
alias: 'o',
describe: "'tis a mighty fine option",
demand: true
})
.command('run', "Arrr, ya best be knowin' what yer doin'")
.example('$0 run foo', "shiver me timbers, here's an example for ye")
@@ -298,7 +309,7 @@ function Argv$reset() {
.argv
console.log('hello!');
} else if (command === 'world'){
} else if (command === 'world') {
ya.reset()
.usage('$0 world')
.help('h')

16
yargs/yargs.d.ts vendored
View File

@@ -21,7 +21,7 @@ declare module "yargs" {
alias(shortName: string, longName: string): Argv;
alias(aliases: { [shortName: string]: string }): Argv;
alias(aliases: { [shortName: string]: string[] }): Argv;
array(key: string): Argv;
array(keys: string[]): Argv;
@@ -64,7 +64,11 @@ 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;
command(command: string, description: string, handler: (args: Argv) => void): Argv;
command(command: string, description: string, builder: (args: Argv) => Options): Argv;
command(command: string, description: string, builder: { [optionName: string]: Options }): Argv;
command(command: string, description: string, builder: { [optionName: string]: Options }, handler: (args: Argv) => void): Argv;
command(command: string, description: string, builder: (args: Argv) => Options, handler: (args: Argv) => void): Argv;
completion(cmd: string, fn?: SyncCompletionFunction): Argv;
completion(cmd: string, description?: string, fn?: SyncCompletionFunction): Argv;
@@ -93,7 +97,7 @@ declare module "yargs" {
help(): string;
help(option: string, description?: string): Argv;
env(prefix?: string): Argv;
env(enable: boolean): Argv;
@@ -108,13 +112,13 @@ declare module "yargs" {
showHelp(func?: (message: string) => any): Argv;
exitProcess(enabled:boolean): Argv;
global(key: string): Argv;
global(keys: string[]): Argv;
group(key: string, groupName: string): Argv;
group(keys: string[], groupName: string): Argv;
nargs(key: string, count: number): Argv;
nargs(nargs: { [key: string]: number }): Argv;