-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
executable file
·71 lines (66 loc) · 2.48 KB
/
Copy pathcli.ts
File metadata and controls
executable file
·71 lines (66 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bun
import { printInitSummary, parseInitOptions, runInitCommand } from "./commands/init";
import { runHookCommand } from "./commands/hook";
import { parseReportOptions, runReportCommand } from "./commands/report";
import { runDoctorCommand } from "./commands/doctor";
import { runProjectsCommand } from "./commands/projects";
import { parseArgv } from "./lib/argv";
/** True only for commands that intentionally keep the process alive after
* main() resolves (currently just `dashboard`, whose Bun.serve() call
* returns as soon as it starts listening, not when it stops) — used to
* skip the process.exit() call below that every other command wants. */
let keepAlive = false;
async function main(): Promise<number> {
const [command, ...rest] = process.argv.slice(2);
switch (command) {
case "init": {
const parsed = parseArgv(rest);
const options = parseInitOptions(parsed);
const outcomes = await runInitCommand(process.cwd(), options);
printInitSummary(outcomes);
return 0;
}
case "hook": {
const [tool, event, base64Payload] = rest;
return runHookCommand(tool ?? "", event, base64Payload);
}
case "report": {
const parsed = parseArgv(rest);
const options = await parseReportOptions(parsed, Date.now());
await runReportCommand(options);
return 0;
}
case "dashboard": {
const { runDashboardCommand } = await import("./commands/dashboard");
await runDashboardCommand();
keepAlive = true;
return 0;
}
case "doctor": {
await runDoctorCommand(process.cwd());
return Number(process.exitCode ?? 0);
}
case "projects": {
const [subcommand, ...projectRest] = rest;
const parsed = parseArgv(projectRest);
await runProjectsCommand(subcommand, parsed);
return Number(process.exitCode ?? 0);
}
default: {
console.log(`commitly — track billable hours across Claude Code, Codex CLI, and OpenCode.
Usage:
commitly init [--scope user|project] [--tools claude-code,codex,opencode] [--force]
commitly report [--from DATE] [--to DATE] [--project NAME] [--client NAME] [--tool NAME] [--format csv|html] [--out PATH] [--with-git=false]
commitly dashboard
commitly doctor
commitly projects list|add|set-rate [...flags]
commitly hook <tool> <event> (internal — invoked by registered hooks)
`);
return command ? 1 : 0;
}
}
}
if (import.meta.main) {
const code = await main();
if (!keepAlive) process.exit(code);
}