* Handles the command line arguments and executes * the matching ace commands * * @param argv - Command line arguments array
(argv: string[])
| 64 | * @param argv - Command line arguments array |
| 65 | */ |
| 66 | async handle(argv: string[]) { |
| 67 | const app = this.#ignitor.createApp('console') |
| 68 | await app.init() |
| 69 | |
| 70 | const { createAceKernel } = await import('../../modules/ace/create_kernel.js') |
| 71 | const commandNameIndex = argv.findIndex((value) => !value.startsWith('-')) |
| 72 | const commandName = argv[commandNameIndex] |
| 73 | |
| 74 | const kernel = createAceKernel(app, commandName) |
| 75 | app.container.bindValue('ace', kernel) |
| 76 | |
| 77 | /** |
| 78 | * Hook into kernel and start the app when the |
| 79 | * command needs the app. |
| 80 | * |
| 81 | * Since multiple commands can be executed in a single process, |
| 82 | * we add a check to only start the app only once. |
| 83 | */ |
| 84 | kernel.loading(async (metaData) => { |
| 85 | if (metaData.options.startApp && !app.isReady) { |
| 86 | if (metaData.commandName === 'repl') { |
| 87 | app.setEnvironment('repl') |
| 88 | } |
| 89 | await app.boot() |
| 90 | await app.start(() => {}) |
| 91 | } |
| 92 | }) |
| 93 | |
| 94 | await this.#configureCallback(app) |
| 95 | |
| 96 | /** |
| 97 | * Register terminating callback BEFORE handling the command. |
| 98 | * This ensures the callback is registered even if a staysAlive |
| 99 | * command calls app.terminate() during its execution. |
| 100 | */ |
| 101 | app.terminating(() => { |
| 102 | const mainCommand = kernel.getMainCommand() |
| 103 | if (mainCommand?.staysAlive) { |
| 104 | process.exitCode = mainCommand.exitCode |
| 105 | } |
| 106 | }) |
| 107 | |
| 108 | /** |
| 109 | * Handle command line args |
| 110 | */ |
| 111 | await kernel.handle(argv) |
| 112 | |
| 113 | /** |
| 114 | * Terminate the app when the command does not want to |
| 115 | * hold a long running process |
| 116 | */ |
| 117 | const mainCommand = kernel.getMainCommand() |
| 118 | if (!mainCommand || !mainCommand.staysAlive) { |
| 119 | process.exitCode = kernel.exitCode |
| 120 | await app.terminate() |
| 121 | } |
| 122 | } |
| 123 | } |
nothing calls this directly
no test coverage detected