* Add hook for life cycle event. * * @param {string} event * @param {Function} listener * @return {Command} `this` command for chaining
(event, listener)
| 486 | */ |
| 487 | |
| 488 | hook(event, listener) { |
| 489 | const allowedValues = ['preSubcommand', 'preAction', 'postAction']; |
| 490 | if (!allowedValues.includes(event)) { |
| 491 | throw new Error(`Unexpected value for event passed to hook : '${event}'. |
| 492 | Expecting one of '${allowedValues.join("', '")}'`); |
| 493 | } |
| 494 | if (this._lifeCycleHooks[event]) { |
| 495 | this._lifeCycleHooks[event].push(listener); |
| 496 | } else { |
| 497 | this._lifeCycleHooks[event] = [listener]; |
| 498 | } |
| 499 | return this; |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Register callback to use as replacement for calling process.exit. |
no outgoing calls
no test coverage detected