diff --git a/yargs/index.d.ts b/yargs/index.d.ts index 8f6f7cf531..238f5d1edd 100644 --- a/yargs/index.d.ts +++ b/yargs/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for yargs +// Type definitions for yargs 6.3.0 // Project: https://github.com/chevex/yargs -// Definitions by: Martin Poelstra , Mizunashi Mana +// Definitions by: Martin Poelstra , Mizunashi Mana , Jeffery Grajkowski // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace yargs { @@ -18,12 +18,6 @@ declare namespace yargs { terminalWidth(): number; - terminalWidth(): number; - - terminalWidth(): number; - - terminalWidth(): number; - alias(shortName: string, longName: string): Argv; alias(aliases: { [shortName: string]: string }): Argv; alias(aliases: { [shortName: string]: string[] }): Argv; @@ -31,8 +25,8 @@ declare namespace yargs { array(key: string): Argv; array(keys: string[]): Argv; - default(key: string, value: any): Argv; - default(defaults: { [key: string]: any }): Argv; + default(key: string, value: any, description?: string): Argv; + default(defaults: { [key: string]: any }, description?: string): Argv; demand(key: string, msg: string): Argv; demand(key: string, required?: boolean): Argv; @@ -79,6 +73,7 @@ declare namespace yargs { commandDir(dir: string, opts?: RequireDirectoryOptions): Argv; + completion(): Argv; completion(cmd: string, fn?: AsyncCompletionFunction): Argv; completion(cmd: string, fn?: SyncCompletionFunction): Argv; completion(cmd: string, description?: string, fn?: AsyncCompletionFunction): Argv; @@ -94,18 +89,27 @@ declare namespace yargs { string(key: string): Argv; string(keys: string[]): Argv; + number(key: string): Argv; + number(keys: string[]): Argv; + choices(choices: Object): Argv; choices(key: string, values: any[]): Argv; - config(key: string): Argv; - config(keys: string[]): Argv; + config(): Argv; + config(explicitConfigurationObject: Object): Argv; + config(key: string, description?: string, parseFn?: (configPath: string) => Object): Argv; + config(keys: string[], description?: string, parseFn?: (configPath: string) => Object): Argv; + config(key: string, parseFn: (configPath: string) => Object): Argv; + config(keys: string[], parseFn: (configPath: string) => Object): Argv; wrap(columns: number): Argv; strict(): Argv; help(): Argv; - help(option: string, description?: string): Argv; + help(enableExplicit: boolean): Argv; + help(option: string, enableExplicit: boolean): Argv; + help(option: string, description?: string, enableExplicit?: boolean): Argv; env(prefix?: string): Argv; env(enable: boolean): Argv; @@ -118,7 +122,7 @@ declare namespace yargs { showHelpOnFail(enable: boolean, message?: string): Argv; - showHelp(func?: (message: string) => any): Argv; + showHelp(consoleLevel?: string): Argv; exitProcess(enabled: boolean): Argv; @@ -140,10 +144,26 @@ declare namespace yargs { count(key: string): Argv; count(keys: string[]): Argv; - fail(func: (msg: string, err: Error) => any): Argv; + fail(func: (msg: string, err: Error) => any): Argv; coerce(key: string|string[], func: (arg: T) => U): Argv; coerce(opts: { [key: string]: (arg: T) => U; }): Argv; + + getCompletion(args: string[], done: (completions: string[]) => void): Argv; + + pkgConf(key: string, cwd?: string): Argv; + pkgConf(keys: string[], cwd?: string): Argv; + + recommendCommands(): Argv; + + showCompletionScript(): Argv; + + skipValidation(key: string): Argv; + skipValidation(keys: string[]): Argv; + + updateLocale(obj: Object): Argv; + + updateStrings(obj: {[key: string]: string}): Argv; } interface RequireDirectoryOptions { diff --git a/yargs/yargs-tests.ts b/yargs/yargs-tests.ts index 02bcf0695d..011d305621 100644 --- a/yargs/yargs-tests.ts +++ b/yargs/yargs-tests.ts @@ -411,3 +411,92 @@ function Argv$count() { .count(['w', 'h']) .argv } + +function Argv$number() { + var ya = yargs + .number('n') + .number(['width', 'height']) + .argv +} + +function Argv$updateStrings() { + var ya = yargs + .command('run', 'the run command') + .help('help') + .updateStrings({ + 'Commands:': 'My Commands -->\n' + }) + .wrap(null) + .argv +} + +function Argv$default() { + var ya = yargs + .default('random', function randomValue() { + return Math.random() * 256; + }) + .argv +} + +function Argv$configObject() { + var ya = yargs + .config({foo: 1, bar: 2}) + .argv +} + +function Argv$configParseFunction() { + var ya = yargs + .config('settings', function (configPath) { + return JSON.parse(fs.readFileSync(configPath, 'utf-8')) + }) + .config('settings', 'description', function (configPath) { + return JSON.parse(fs.readFileSync(configPath, 'utf-8')) + }) + .argv +} + +function Argv$helpDescriptionExplicit() { + var ya = yargs + .help('help', 'description', true) + .argv +} + +function Argv$showHelpConsoleLevel() { + yargs.showHelp("log"); //prints to stdout using console.log() +} + +function Argv$getCompletion() { + var ya = yargs + .option('foobar', {}) + .option('foobaz', {}) + .completion() + .getCompletion(['./test.js', '--foo'], function (completions) { + console.log(completions) + }) + .argv +} + +function Argv$pkgConf() { + var ya = yargs + .pkgConf(['key1', 'key2'], 'configFile.json') + .argv +} + +function Argv$recommendCommands() { + var ya = yargs + .recommendCommands() + .argv +} + +function Argv$showCompletionScript() { + var ya = yargs + .showCompletionScript() + .argv +} + +function Argv$skipValidation() { + var ya = yargs + .skipValidation('arg1') + .skipValidation(['arg2', 'arg3']) + .argv +}