* Get or set the program version. * * 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. * * @param {string} [str] * @param {string} [flags] * @param {str
(str, flags, description)
| 2207 | */ |
| 2208 | |
| 2209 | version(str, flags, description) { |
| 2210 | if (str === undefined) return this._version; |
| 2211 | this._version = str; |
| 2212 | flags = flags || '-V, --version'; |
| 2213 | description = description || 'output the version number'; |
| 2214 | const versionOption = this.createOption(flags, description); |
| 2215 | this._versionOptionName = versionOption.attributeName(); |
| 2216 | this._registerOption(versionOption); |
| 2217 | |
| 2218 | this.on('option:' + versionOption.name(), () => { |
| 2219 | this._outputConfiguration.writeOut(`${str}\n`); |
| 2220 | this._exit(0, 'commander.version', str); |
| 2221 | }); |
| 2222 | return this; |
| 2223 | } |
| 2224 | |
| 2225 | /** |
| 2226 | * Set the description. |
no test coverage detected