* Executes the lifecycle hooks and the run method from the command
()
| 103 | * Executes the lifecycle hooks and the run method from the command |
| 104 | */ |
| 105 | async exec() { |
| 106 | this.hydrate() |
| 107 | |
| 108 | try { |
| 109 | /** |
| 110 | * Executing the template methods |
| 111 | */ |
| 112 | this.prepare && (await this.app.container.call<any, 'prepare'>(this, 'prepare')) |
| 113 | this.interact && (await this.app.container.call<any, 'interact'>(this, 'interact')) |
| 114 | const result = await this.app.container.call<BaseCommand, 'run'>(this, 'run') |
| 115 | |
| 116 | /** |
| 117 | * Set exit code |
| 118 | */ |
| 119 | this.result = this.result === undefined ? result : this.result |
| 120 | this.exitCode = this.exitCode ?? 0 |
| 121 | } catch (error) { |
| 122 | this.error = error |
| 123 | this.exitCode = this.exitCode ?? 1 |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Run the completed method (if exists) and check if has handled |
| 128 | * the error |
| 129 | */ |
| 130 | let errorHandled = this.completed |
| 131 | ? await this.app.container.call<any, 'completed'>(this, 'completed') |
| 132 | : false |
| 133 | |
| 134 | if (this.error && !errorHandled) { |
| 135 | await this.kernel.errorHandler.render(this.error, this.kernel) |
| 136 | } |
| 137 | |
| 138 | return this.result |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Terminate the application gracefully. This method should be preferred over |
no test coverage detected