( deps: LifecycleCommandDeps, json: boolean, body: (mgr: ServiceManager) => Promise<Record<string, unknown>>, )
| 157 | } |
| 158 | |
| 159 | async function runLifecycle( |
| 160 | deps: LifecycleCommandDeps, |
| 161 | json: boolean, |
| 162 | body: (mgr: ServiceManager) => Promise<Record<string, unknown>>, |
| 163 | ): Promise<void> { |
| 164 | try { |
| 165 | const mgr = deps.resolveManager(); |
| 166 | const result = await body(mgr); |
| 167 | if (json) { |
| 168 | deps.stdout.write(`${JSON.stringify(result)}\n`); |
| 169 | return; |
| 170 | } |
| 171 | deps.stdout.write(formatHuman(result)); |
| 172 | } catch (error) { |
| 173 | if (error instanceof ServiceUnavailableError || error instanceof ServiceUnsupportedError) { |
| 174 | const payload = { |
| 175 | ok: false, |
| 176 | action: error instanceof ServiceUnavailableError ? 'unavailable' : 'unsupported', |
| 177 | platform: error.platform, |
| 178 | message: error.message, |
| 179 | }; |
| 180 | if (json) { |
| 181 | deps.stdout.write(`${JSON.stringify(payload)}\n`); |
| 182 | } else { |
| 183 | deps.stderr.write(`${error.message}\n`); |
| 184 | } |
| 185 | process.exit(2); |
| 186 | return; |
| 187 | } |
| 188 | if (json) { |
| 189 | deps.stdout.write( |
| 190 | `${JSON.stringify({ ok: false, message: error instanceof Error ? error.message : String(error) })}\n`, |
| 191 | ); |
| 192 | } else { |
| 193 | deps.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`); |
| 194 | } |
| 195 | process.exit(1); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | function formatHuman(result: Record<string, unknown>): string { |
| 200 | const rawAction = result['action']; |
no test coverage detected