index.ts92 lines · main
| 1 | import { printHelp } from './commands/help.js'; |
| 2 | import { runAi } from './commands/ai.js'; |
| 3 | import { runAuth } from './commands/auth.js'; |
| 4 | import { runDb } from './commands/db.js'; |
| 5 | import { runDeploy } from './commands/deploy.js'; |
| 6 | import { runDev } from './commands/dev.js'; |
| 7 | import { runDoctor } from './commands/doctor.js'; |
| 8 | import { runEnv } from './commands/env.js'; |
| 9 | import { runExport } from './commands/export.js'; |
| 10 | import { runImport } from './commands/import.js'; |
| 11 | import { runInit } from './commands/init.js'; |
| 12 | import { runInvoke } from './commands/invoke.js'; |
| 13 | import { runConnect } from './commands/connect.js'; |
| 14 | import { runLink } from './commands/link.js'; |
| 15 | import { runLogin } from './commands/login.js'; |
| 16 | import { runLogout } from './commands/logout.js'; |
| 17 | import { runLogs } from './commands/logs.js'; |
| 18 | import { runProjects } from './commands/projects.js'; |
| 19 | import { runSetupCommand } from './commands/setup.js'; |
| 20 | import { runStorage } from './commands/storage.js'; |
| 21 | import { printVersion } from './commands/version.js'; |
| 22 | import { runWhoami } from './commands/whoami.js'; |
| 23 | import { readProjectConfig } from './project-config.js'; |
| 24 | |
| 25 | export async function run(argv: readonly string[]): Promise<number> { |
| 26 | const [first, ...rest] = argv; |
| 27 | |
| 28 | if (!first) { |
| 29 | // Convex-style default: unlinked folder → setup; linked → watch. |
| 30 | const local = await readProjectConfig(); |
| 31 | if (!local?.projectId) { |
| 32 | return runSetupCommand([]); |
| 33 | } |
| 34 | return runDev([]); |
| 35 | } |
| 36 | if (first === '--help' || first === '-h' || first === 'help') { |
| 37 | printHelp(); |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | if (first === '--version' || first === '-v' || first === 'version') { |
| 42 | printVersion(); |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | switch (first) { |
| 47 | case 'setup': |
| 48 | return runSetupCommand(rest); |
| 49 | case 'init': |
| 50 | return runInit(rest); |
| 51 | case 'connect': |
| 52 | return runConnect(rest); |
| 53 | case 'link': |
| 54 | return runLink(rest); |
| 55 | case 'login': |
| 56 | return runLogin(rest); |
| 57 | case 'logout': |
| 58 | return runLogout(rest); |
| 59 | case 'whoami': |
| 60 | return runWhoami(); |
| 61 | case 'deploy': |
| 62 | return runDeploy(rest); |
| 63 | case 'invoke': |
| 64 | return runInvoke(rest); |
| 65 | case 'env': |
| 66 | return runEnv(rest); |
| 67 | case 'db': |
| 68 | return runDb(rest); |
| 69 | case 'logs': |
| 70 | return runLogs(rest); |
| 71 | case 'dev': |
| 72 | return runDev(rest); |
| 73 | case 'projects': |
| 74 | return runProjects(rest); |
| 75 | case 'export': |
| 76 | return runExport(rest); |
| 77 | case 'import': |
| 78 | return runImport(rest); |
| 79 | case 'doctor': |
| 80 | return runDoctor(rest); |
| 81 | case 'ai': |
| 82 | return runAi(rest); |
| 83 | case 'auth': |
| 84 | return runAuth(rest); |
| 85 | case 'storage': |
| 86 | return runStorage(rest); |
| 87 | } |
| 88 | |
| 89 | process.stderr.write(`briven: unknown command '${first}'\n`); |
| 90 | process.stderr.write(`run 'briven --help' for usage\n`); |
| 91 | return 1; |
| 92 | } |