| 52 | } |
| 53 | |
| 54 | export async function handleMainCommand( |
| 55 | opts: CLIOptions, |
| 56 | version: string, |
| 57 | ): Promise<MainCommandOutcome> { |
| 58 | let validated: ReturnType<typeof validateOptions>; |
| 59 | try { |
| 60 | validated = validateOptions(opts); |
| 61 | } catch (error) { |
| 62 | if (error instanceof OptionConflictError) { |
| 63 | process.stderr.write(`error: ${error.message}\n`); |
| 64 | process.exit(1); |
| 65 | } |
| 66 | throw error; |
| 67 | } |
| 68 | |
| 69 | const preflightResult = await runUpdatePreflight( |
| 70 | version, |
| 71 | validated.uiMode === 'print' ? { track, isTTY: false } : { track }, |
| 72 | ); |
| 73 | if (preflightResult === 'exit') { |
| 74 | process.exit(0); |
| 75 | } |
| 76 | |
| 77 | if (validated.uiMode === 'print') { |
| 78 | await runPrompt(validated.options, version); |
| 79 | return { headlessCompleted: true }; |
| 80 | } |
| 81 | |
| 82 | await runShell(validated.options, version); |
| 83 | return { headlessCompleted: false }; |
| 84 | } |
| 85 | |
| 86 | /** `kimi migrate`: launch the migration screen only, then exit. */ |
| 87 | async function handleMigrateCommand(version: string): Promise<void> { |