* Display error message and exit (or call exitOverride). * * @param {string} message * @param {object} [errorOptions] * @param {string} [errorOptions.code] - an id string representing the error * @param {number} [errorOptions.exitCode] - used with process.exit
(message, errorOptions)
| 1950 | * @param {number} [errorOptions.exitCode] - used with process.exit |
| 1951 | */ |
| 1952 | error(message, errorOptions) { |
| 1953 | // output handling |
| 1954 | this._outputConfiguration.outputError( |
| 1955 | `${message}\n`, |
| 1956 | this._outputConfiguration.writeErr, |
| 1957 | ); |
| 1958 | if (typeof this._showHelpAfterError === 'string') { |
| 1959 | this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`); |
| 1960 | } else if (this._showHelpAfterError) { |
| 1961 | this._outputConfiguration.writeErr('\n'); |
| 1962 | this.outputHelp({ error: true }); |
| 1963 | } |
| 1964 | |
| 1965 | // exit handling |
| 1966 | const config = errorOptions || {}; |
| 1967 | const exitCode = config.exitCode || 1; |
| 1968 | const code = config.code || 'commander.error'; |
| 1969 | this._exit(exitCode, code, message); |
| 1970 | } |
| 1971 | |
| 1972 | /** |
| 1973 | * Apply any option related environment variables, if option does |
no test coverage detected