From 0f810245494ccf13a35b7786d021b30fc95ecad5 Mon Sep 17 00:00:00 2001 From: Mael Le Guen Date: Thu, 6 Aug 2020 03:52:41 +0200 Subject: [PATCH] fix(yargs): add missing command(module) signature (#1707) Close #1704 --- lib/command.ts | 5 ++--- lib/yargs.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/command.ts b/lib/command.ts index ab0328522..26dc8b248 100644 --- a/lib/command.ts +++ b/lib/command.ts @@ -465,10 +465,9 @@ export interface CommandInstance { callerFile: string, opts?: RequireDirectoryOptions ): void - addHandler (handler: CommandHandlerDefinition): void addHandler ( - cmd: string | string[], - description: CommandHandler['description'], + cmd: string | string[] | CommandHandlerDefinition, + description?: CommandHandler['description'], builder?: CommandBuilderDefinition | CommandBuilder, handler?: CommandHandlerCallback, commandMiddleware?: Middleware[], diff --git a/lib/yargs.ts b/lib/yargs.ts index 282df7b0b..c0fdea021 100644 --- a/lib/yargs.ts +++ b/lib/yargs.ts @@ -1,4 +1,4 @@ -import { CommandInstance, CommandHandler, CommandBuilderDefinition, CommandBuilder, CommandHandlerCallback, FinishCommandHandler, command as Command } from './command' +import { CommandInstance, CommandHandler, CommandBuilderDefinition, CommandBuilder, CommandHandlerCallback, FinishCommandHandler, command as Command, CommandHandlerDefinition } from './command' import { Dictionary, assertNotStrictEqual, KeyOf, DictionaryKeyof, ValueOf, objectKeys, assertSingleKey } from './common-types' import { Arguments as ParserArguments, @@ -463,7 +463,14 @@ export function Yargs (processArgs: string | string[] = [], cwd = process.cwd(), return self } - self.command = function (cmd, description, builder, handler, middlewares, deprecated) { + self.command = function ( + cmd: string | string[] | CommandHandlerDefinition, + description?: CommandHandler['description'], + builder?: CommandBuilderDefinition | CommandBuilder, + handler?: CommandHandlerCallback, + middlewares?: Middleware[], + deprecated?: boolean + ) { argsert(' [string|boolean] [function|object] [function] [array] [boolean|string]', [cmd, description, builder, handler, middlewares, deprecated], arguments.length) command.addHandler(cmd, description, builder, handler, middlewares, deprecated) return self @@ -1446,6 +1453,7 @@ export interface YargsInstance { (keys: string | string[], coerceCallback: CoerceCallback): YargsInstance (keyCoerceCallbacks: Dictionary): YargsInstance } + command (handler: CommandHandlerDefinition): YargsInstance command ( cmd: string | string[], description: CommandHandler['description'],