From ba6592f515705aa181e65834b6b1c36b72873d4a Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Tue, 30 Jan 2018 23:30:51 -0700 Subject: [PATCH] only register the option:version event once - create Option directly to avoid registering the option:version event twice - defer to the Option instance to resolve the long name of the option for the event --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 36f3b9b1b..c467b10f7 100644 --- a/index.js +++ b/index.js @@ -855,9 +855,9 @@ Command.prototype.version = function(str, flags) { if (arguments.length === 0) return this._version; this._version = str; flags = flags || '-V, --version'; - var longOptIndex = flags.indexOf('--'); - this._versionOptionName = ~longOptIndex ? flags.substr(longOptIndex + 2) : 'version'; - this.option(flags, 'output the version number'); + var versionOption = new Option(flags, 'output the version number'); + this._versionOptionName = versionOption.long.substr(2) || 'version'; + this.options.push(versionOption); this.on('option:' + this._versionOptionName, function() { process.stdout.write(str + '\n'); process.exit(0);