Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#7670 from olivr70/master
Browse files Browse the repository at this point in the history
Added missing functions from version 3.31
  • Loading branch information
horiuchi committed Jan 20, 2016
2 parents 14c9d4e + 6a28750 commit 4887243
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
64 changes: 64 additions & 0 deletions yargs/yargs-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ function Argv$options() {
;
}

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
}

function command() {
var argv = yargs
.usage('npm <command>')
Expand Down Expand Up @@ -208,4 +218,58 @@ function Argv$version() {

var argv3 = yargs
.version('1.0.0', '--version', 'description');

var argv4 = yargs
.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
})
.command('run', "Arrr, ya best be knowin' what yer doin'")
.example('$0 run foo', "shiver me timbers, here's an example for ye")
.help('help')
.wrap(70)
.locale('pirate')
.argv
}

function Argv$epilogue() {
var argv = yargs
.epilogue('for more information, find our manual at http://example.com');
}

function Argv$reset() {
var ya = yargs
.usage('$0 command')
.command('hello', 'hello command')
.command('world', 'world command')
.demand(1, 'must provide a valid command'),
argv = yargs.argv,
command = argv._[0];

if (command === 'hello') {
ya.reset()
.usage('$0 hello')
.help('h')
.example('$0 hello', 'print the hello message!')
.argv

console.log('hello!');
} else if (command === 'world'){
ya.reset()
.usage('$0 world')
.help('h')
.example('$0 world', 'print the world message!')
.argv

console.log('world!');
} else {
ya.showHelp();
}
}
17 changes: 17 additions & 0 deletions yargs/yargs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ declare module "yargs" {
(...args: any[]): any;
parse(...args: any[]): any;

reset(): Argv;

locale(): string;
locale(loc:string): Argv;

detectLocale(detect:boolean): Argv;

alias(shortName: string, longName: string): Argv;
alias(aliases: { [shortName: string]: string }): Argv;
alias(aliases: { [shortName: string]: string[] }): Argv;
Expand Down Expand Up @@ -71,6 +78,9 @@ declare module "yargs" {
string(key: string): Argv;
string(keys: string[]): Argv;

choices(choices: Object): Argv;
choices(key: string, values:any[]): Argv;

config(key: string): Argv;
config(keys: string[]): Argv;

Expand All @@ -81,12 +91,18 @@ declare module "yargs" {
help(): string;
help(option: string, description?: string): Argv;

epilog(msg: string): Argv;
epilogue(msg: string): Argv;

version(version: string, option?: string, description?: string): Argv;
version(version: () => string, option?: string, description?: string): Argv;

showHelpOnFail(enable: boolean, message?: string): Argv;

showHelp(func?: (message: string) => any): Argv;

exitProcess(enabled:boolean): Argv;

/* Undocumented */

normalize(key: string): Argv;
Expand Down Expand Up @@ -115,6 +131,7 @@ declare module "yargs" {
description?: any;
desc?: any;
requiresArg?: any;
choices?:string[];
}

type SyncCompletionFunction = (current: string, argv: any) => string[];
Expand Down

0 comments on commit 4887243

Please sign in to comment.