From 3a425d67319f23b1f0b1fbd1dc9d8ac25a4c5a7b Mon Sep 17 00:00:00 2001 From: Niklas Mollenhauer Date: Fri, 18 Nov 2016 18:58:23 +0100 Subject: [PATCH 1/2] Fix builder function return type --- yargs/index.d.ts | 4 ++-- yargs/yargs-tests.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/yargs/index.d.ts b/yargs/index.d.ts index fa82e2490e..69accf9d70 100644 --- a/yargs/index.d.ts +++ b/yargs/index.d.ts @@ -66,10 +66,10 @@ declare namespace yargs { command(command: string, description: string): 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: (args: Argv) => Argv): 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; + command(command: string, description: string, builder: (args: Argv) => Argv, handler: (args: Argv) => void): Argv; command(command: string, description: string, module: CommandModule): Argv; command(module: CommandModule): Argv; diff --git a/yargs/yargs-tests.ts b/yargs/yargs-tests.ts index 8fb693803a..c88f9954d8 100644 --- a/yargs/yargs-tests.ts +++ b/yargs/yargs-tests.ts @@ -226,6 +226,33 @@ function command() { }) .help('help') .argv; + + yargs + .command('get', 'make a get HTTP request', function (yargs) { + return yargs.option('url', { + alias: 'u', + default: 'http://yargs.js.org/' + }) + }) + .help() + .argv + + yargs + .command( + 'get', + 'make a get HTTP request', + function (yargs) { + return yargs.option('u', { + alias: 'url', + describe: 'the URL to make an HTTP request to' + }) + }, + function (argv) { + console.dir(argv) + } + ) + .help() + .argv } function completion_sync() { From 19f558b6c6aa49f1f627f6cc8f78f4ee22348746 Mon Sep 17 00:00:00 2001 From: Niklas Mollenhauer Date: Sat, 19 Nov 2016 21:20:00 +0100 Subject: [PATCH 2/2] Fix command overloads --- yargs/index.d.ts | 5 ++--- yargs/yargs-tests.ts | 11 +++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/yargs/index.d.ts b/yargs/index.d.ts index 69accf9d70..a1de96fbd5 100644 --- a/yargs/index.d.ts +++ b/yargs/index.d.ts @@ -65,11 +65,10 @@ declare namespace yargs { usage(options?: { [key: string]: Options }): Argv; command(command: string, description: string): Argv; - command(command: string, description: string, handler: (args: Argv) => void): Argv; command(command: string, description: string, builder: (args: Argv) => Argv): 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) => Argv, handler: (args: Argv) => void): Argv; + command(command: string, description: string, builder: { [optionName: string]: Options }, handler: (args: any) => void): Argv; + command(command: string, description: string, builder: (args: Argv) => Argv, handler: (args: any) => void): Argv; command(command: string, description: string, module: CommandModule): Argv; command(module: CommandModule): Argv; diff --git a/yargs/yargs-tests.ts b/yargs/yargs-tests.ts index c88f9954d8..bcdd0e5368 100644 --- a/yargs/yargs-tests.ts +++ b/yargs/yargs-tests.ts @@ -188,14 +188,13 @@ function command() { var argv = yargs .usage('npm ') .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', { + .command('publish', 'shiver me timbers, should you be sharing all that', yargs => + yargs.option('f', { alias: 'force', description: 'yar, it usually be a bad idea' }) .help('help') - .argv; - }) + ) .command("build", "arghh, build it mate", { tag: { default: true, @@ -247,8 +246,8 @@ function command() { describe: 'the URL to make an HTTP request to' }) }, - function (argv) { - console.dir(argv) + function (argv: { url: string }) { + console.dir(argv.url) } ) .help()