Skip to content

Commit

Permalink
only register the option:version event once
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
mojavelinux committed Jan 31, 2018
1 parent f5abcdb commit ba6592f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -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);
Expand Down

0 comments on commit ba6592f

Please sign in to comment.