Skip to content
Myr

resolves #560 respect custom name for version option

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Dan Allen · committed by Dan Allen · parent e5d8f04 · Browse files · 4 files+45 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+45 added−3 removed

  • tests:+40 added−0 removed
  • other:+5 added−3 removed

4 files+45 added−3 removed

added:test/test.options.version.custom.js+20 added
added:test/test.options.version.js+20 added
modified:index.js+4 added-2 removed
772 unmodified lines
773 , len = this.options.length;774775 for (var i = 0 ; i < len; i++) {776 var key = this.options[i].attributeName();777 result[key] = key === 'version' ? this._version : this[key];777 result[key] = key === this._versionOptionName ? this._version : this[key];778 }779 return result;780};781
74 unmodified lines
856Command.prototype.version = function(str, flags) {857 if (0 == arguments.length) return this._version;858 this._version = str;859 flags = flags || '-V, --version';860 var longOptIndex = flags.indexOf('--')861 this._versionOptionName = ~longOptIndex ? flags.substr(longOptIndex + 2) : 'version'862 this.option(flags, 'output the version number');861 this.on('option:version', function() {863 this.on('option:' + this._versionOptionName, function() {864 process.stdout.write(str + '\n');865 process.exit(0);866 });867 return this;
293 unmodified lines
modified:Readme.md+1 added-1 removed
77 unmodified lines
78program79 .version('0.0.1', '-v, --version')80```8182Now the command will accept the `-v` option instead of the `-V` option.82The version flags can be named anything, but the long option is required.8384## Command-specific options8586You can attach options to a command.
322 unmodified lines