| 212 | }; |
| 213 | |
| 214 | async function dispatchKnownCommand( |
| 215 | device: DeviceInfo, |
| 216 | interactor: Interactor, |
| 217 | command: string, |
| 218 | positionals: string[], |
| 219 | outPath: string | undefined, |
| 220 | context: DispatchContext | undefined, |
| 221 | runnerCtx: RunnerContext, |
| 222 | ): Promise<Record<string, unknown> | void> { |
| 223 | // `Object.hasOwn` keeps the lookup behaviorless: any unknown command — |
| 224 | // including inherited keys like `toString` — falls through to the same |
| 225 | // `INVALID_ARGS` error the former `default:` branch threw. |
| 226 | const handler = Object.hasOwn(DISPATCH_HANDLERS, command) |
| 227 | ? DISPATCH_HANDLERS[command as DispatchCommand] |
| 228 | : undefined; |
| 229 | if (!handler) { |
| 230 | throw new AppError('INVALID_ARGS', `Unknown command: ${command}`); |
| 231 | } |
| 232 | return await handler({ device, interactor, positionals, outPath, context, runnerCtx }); |
| 233 | } |
| 234 | |
| 235 | // --------------------------------------------------------------------------- |
| 236 | // Command handlers |