From 6a287502dab374e7d4cbf18ea1ac5dff7f74726a Mon Sep 17 00:00:00 2001 From: Olivier CHEVET Date: Sun, 17 Jan 2016 17:38:52 +0100 Subject: [PATCH] Added missing functions from version 3.31 - reset - epilog/epilogue - locale - detectLocale - choices - exitProcess Added an extra prototype for version, accepting a function argument --- yargs/yargs-tests.ts | 64 ++++++++++++++++++++++++++++++++++++++++++++ yargs/yargs.d.ts | 17 ++++++++++++ 2 files changed, 81 insertions(+) diff --git a/yargs/yargs-tests.ts b/yargs/yargs-tests.ts index f20254990..d504cd181 100644 --- a/yargs/yargs-tests.ts +++ b/yargs/yargs-tests.ts @@ -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 ') @@ -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(); + } } diff --git a/yargs/yargs.d.ts b/yargs/yargs.d.ts index 03b7c05dc..637137fbf 100644 --- a/yargs/yargs.d.ts +++ b/yargs/yargs.d.ts @@ -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; @@ -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; @@ -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; @@ -115,6 +131,7 @@ declare module "yargs" { description?: any; desc?: any; requiresArg?: any; + choices?:string[]; } type SyncCompletionFunction = (current: string, argv: any) => string[];