Skip to content
Myr

Merge pull request #753 from mojavelinux/issue-560-version-option

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

resolves #560 respect custom name for version option

authored by Tomoaki Abe · committed by GitHub · parents 38f41bf, 37359ee · 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
770 unmodified lines
771 len = this.options.length;772773 for (var i = 0; i < len; i++) {774 var key = this.options[i].attributeName();775 result[key] = key === 'version' ? this._version : this[key];775 result[key] = key === this._versionOptionName ? this._version : this[key];776 }777 return result;778};779
74 unmodified lines
854Command.prototype.version = function(str, flags) {855 if (arguments.length === 0) return this._version;856 this._version = str;857 flags = flags || '-V, --version';858 var longOptIndex = flags.indexOf('--')859 this._versionOptionName = ~longOptIndex ? flags.substr(longOptIndex + 2) : 'version'860 this.option(flags, 'output the version number');859 this.on('option:version', function() {861 this.on('option:' + this._versionOptionName, function() {862 process.stdout.write(str + '\n');863 process.exit(0);864 });865 return this;
292 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