index.ts92 lines · main
1import { printHelp } from './commands/help.js';
2import { runAi } from './commands/ai.js';
3import { runAuth } from './commands/auth.js';
4import { runDb } from './commands/db.js';
5import { runDeploy } from './commands/deploy.js';
6import { runDev } from './commands/dev.js';
7import { runDoctor } from './commands/doctor.js';
8import { runEnv } from './commands/env.js';
9import { runExport } from './commands/export.js';
10import { runImport } from './commands/import.js';
11import { runInit } from './commands/init.js';
12import { runInvoke } from './commands/invoke.js';
13import { runConnect } from './commands/connect.js';
14import { runLink } from './commands/link.js';
15import { runLogin } from './commands/login.js';
16import { runLogout } from './commands/logout.js';
17import { runLogs } from './commands/logs.js';
18import { runProjects } from './commands/projects.js';
19import { runSetupCommand } from './commands/setup.js';
20import { runStorage } from './commands/storage.js';
21import { printVersion } from './commands/version.js';
22import { runWhoami } from './commands/whoami.js';
23import { readProjectConfig } from './project-config.js';
24
25export 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}