-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
executable file
·64 lines (57 loc) · 2 KB
/
Copy pathindex.ts
File metadata and controls
executable file
·64 lines (57 loc) · 2 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
import { Commit } from "@/cli/commit";
import { Branch } from "@/cli/branch";
import { Setup } from "@/cli/setup";
import { Doctor } from "@/cli/doctor";
import { ModelCommand } from "@/cli/model";
import { EffortCommand } from "@/cli/effort";
import { AliasCommand } from "@/cli/alias";
import { Update } from "@/cli/update";
import { type CliCommand, parseArgs, showHelp, showVersion } from "@/cli/parser";
import { Future } from "@/libs/future";
import { absurd } from "@/libs/types";
import { checkUpdate } from "@/cli/update";
import color from "picocolors";
const NOTIFIER_COMMANDS = new Set<CliCommand["type"]>(["generate", "setup", "doctor", "model", "effort", "branch", "alias"]);
const main = () => {
const args = process.argv.slice(2);
const action = parseArgs(args).either(
(err): Future<Error, void> => {
console.error(color.red(err.message));
return Future.reject(err);
},
(command): Future<Error, void> => {
if (NOTIFIER_COMMANDS.has(command.type)) checkUpdate();
switch (command.type) {
case "generate":
return Commit.create().chain((c) => c.run());
case "setup":
return Setup.create().chain((s) => s.run());
case "doctor":
return Doctor.create().run();
case "model":
return ModelCommand.create().chain((m) => m.run());
case "effort":
return EffortCommand.create().chain((e) => e.run());
case "branch":
return Branch.create().chain((b) => b.run());
case "alias":
return AliasCommand.create(command.action).chain((a) => a.run());
case "update":
return Update.create().run();
case "version":
showVersion();
return Future.resolve(undefined);
case "help":
showHelp();
return Future.resolve(undefined);
default:
absurd(command, `Unhandled command type: ${command}`);
}
}
);
action.fork(
(_) => process.exit(1),
() => process.exit(0)
);
};
main();