| 1 | import { dispatch, type Registry } from "./cli.js"; |
| 2 | import { adminCommands, agentGroup, secretGroup, tokenGroup, variableGroup } from "./commands/admin.js"; |
| 3 | import { authCommands, authGroup } from "./commands/auth.js"; |
| 4 | import { issueGroup } from "./commands/issue.js"; |
| 5 | import { migrateGroup } from "./commands/migrate.js"; |
| 6 | import { prGroup } from "./commands/pr.js"; |
| 7 | import { repoGroup } from "./commands/repo.js"; |
| 8 | import { runGroup } from "./commands/run.js"; |
| 9 | import { runnerCommand } from "./commands/runner.js"; |
| 10 | import { workflowGroup } from "./commands/workflow.js"; |
| 11 | import { CliError, processIo, type Io } from "./io.js"; |
| 12 | |
| 13 | export const registry: Registry = { |
| 14 | groups: [authGroup, repoGroup, prGroup, issueGroup, runGroup, workflowGroup, secretGroup, variableGroup, tokenGroup, agentGroup, migrateGroup], |
| 15 | commands: [...authCommands, ...adminCommands, runnerCommand], |
| 16 | }; |
| 17 | |
| 18 | /** Runs the CLI and returns its exit code (never calls process.exit). */ |
| 19 | export async function main(argv: string[], io: Io = processIo()): Promise<number> { |
| 20 | try { |
| 21 | return await dispatch(registry, argv, io); |
| 22 | } catch (e) { |
| 23 | if (e instanceof CliError) { |
| 24 | io.stderr.write(`error: ${e.message}\n`); |
| 25 | return e.code; |
| 26 | } |
| 27 | io.stderr.write(`error: ${e instanceof Error ? (e.stack ?? e.message) : String(e)}\n`); |
| 28 | return 1; |
| 29 | } |
| 30 | } |