From e93db25af6a8c188e7c305e4f40fecf0c801e67a Mon Sep 17 00:00:00 2001 From: John Gee Date: Fri, 25 Aug 2023 20:04:48 +1200 Subject: [PATCH 1/2] Update types since .version() returns version. --- lib/command.js | 13 ++++++------- typings/index.d.ts | 4 ++++ typings/index.test-d.ts | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/command.js b/lib/command.js index fb0835316..9d333802b 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1818,17 +1818,16 @@ Expecting one of '${allowedValues.join("', '")}'`); } /** - * Set the program version to `str`. + * Get or set the program version. * - * This method auto-registers the "-V, --version" flag - * which will print the version number when passed. + * This method auto-registers the "-V, --version" option which will print the version number. * - * You can optionally supply the flags and description to override the defaults. + * You can optionally supply the flags and description to override the defaults. * - * @param {string} str + * @param {string} [str] * @param {string} [flags] * @param {string} [description] - * @return {this | string} `this` command for chaining, or version string if no arguments + * @return {this | string | undefined} `this` command for chaining, or version string if no arguments */ version(str, flags, description) { @@ -1837,7 +1836,7 @@ Expecting one of '${allowedValues.join("', '")}'`); flags = flags || '-V, --version'; description = description || 'output the version number'; const versionOption = this.createOption(flags, description); - this._versionOptionName = versionOption.attributeName(); + this._versionOptionName = versionOption.attributeName(); // [sic] not defined in constructor, partly legacy, partly only needed at root this.options.push(versionOption); this.on('option:' + versionOption.name(), () => { this._outputConfiguration.writeOut(`${str}\n`); diff --git a/typings/index.d.ts b/typings/index.d.ts index c9d3c314c..8497fd214 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -294,6 +294,10 @@ export class Command { * You can optionally supply the flags and description to override the defaults. */ version(str: string, flags?: string, description?: string): this; + /** + * Get the program version. + */ + version(): string | undefined; /** * Define a command, implemented using an action handler. diff --git a/typings/index.test-d.ts b/typings/index.test-d.ts index 5d17dd17a..7296e4cf2 100644 --- a/typings/index.test-d.ts +++ b/typings/index.test-d.ts @@ -36,6 +36,7 @@ expectType(program.parent); expectType(program.version('1.2.3')); expectType(program.version('1.2.3', '-r,--revision')); expectType(program.version('1.2.3', '-r,--revision', 'show revision information')); +expectType(program.version()); // command (and CommandOptions) expectType(program.command('action')); From 4812b4aab3da55cddb9b26b25b247ed4ee0e9b11 Mon Sep 17 00:00:00 2001 From: John Gee Date: Sat, 26 Aug 2023 17:51:29 +1200 Subject: [PATCH 2/2] Remove extra space --- lib/command.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command.js b/lib/command.js index 9d333802b..7cbc6fd3b 100644 --- a/lib/command.js +++ b/lib/command.js @@ -1827,7 +1827,7 @@ Expecting one of '${allowedValues.join("', '")}'`); * @param {string} [str] * @param {string} [flags] * @param {string} [description] - * @return {this | string | undefined} `this` command for chaining, or version string if no arguments + * @return {this | string | undefined} `this` command for chaining, or version string if no arguments */ version(str, flags, description) {