-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
96 lines (86 loc) · 2.61 KB
/
mod.ts
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env -S deno run -A --unstable-worker-options
import {
Command,
CompletionsCommand,
HelpCommand,
JsrProvider,
UpgradeCommand,
} from "./deps/@cliffy/command/mod.ts";
import * as log from "./deps/@std/log/mod.ts";
const LEVEL =
(Deno.env.get("APEX_LOG")?.toUpperCase() as log.LevelName | undefined) ||
"INFO";
await setupLogger(LEVEL);
import * as generate from "./src/commands/generate.ts";
import * as newCmd from "./src/commands/new.ts";
import * as install from "./src/commands/install.ts";
import * as init from "./src/commands/init.ts";
import * as list from "./src/commands/list.ts";
import * as describe from "./src/commands/describe.ts";
import * as watch from "./src/commands/watch.ts";
import * as run from "./src/commands/run.ts";
import { setupLogger } from "./src/utils.ts";
import { RunError } from "./src/task.ts";
// Version bump this on release.
const version = "0.2.5";
// This is necessary so we can modify the argument list.
const args = Array.from(Deno.args);
if (
args.length == 1 &&
args[0] == "__generate" &&
!Deno.stdin.isTerminal()
) {
generate.fromStdin();
} else {
const cli = new Command()
.default("help")
.version(version)
.name("apex")
.description(
"A complete project tool suite based on Apexlang, an interface definition language (IDL) for modeling software.",
)
.command("install", install.command)
.command("new", newCmd.command)
.command("init", init.command)
.command("generate", generate.command)
.command("list", list.command)
.command("describe", describe.command)
.command("watch", watch.command)
.command("run", run.command)
.command(
"upgrade",
new UpgradeCommand({
main: "mod.ts",
args: [
"--allow-read",
"--allow-write",
"--allow-env",
"--allow-net",
"--allow-run",
"--allow-import",
"--unstable-worker-options",
],
provider: [new JsrProvider({ package: "@apexlang/apex" })],
}),
)
.command("help", new HelpCommand().global())
.command("completions", new CompletionsCommand());
const nonFlagArgs = args.filter((v) => !v.startsWith("-"));
const nonApexCommand = nonFlagArgs.length > 0 &&
!cli.getBaseCommand(args[0], true);
// If we have a subcommand that isn't a built-in, treat
// the command as if it were triggered with `apex run`
if (nonApexCommand) {
args.unshift("run");
}
try {
await cli.parse(args);
} catch (e) {
if (e instanceof RunError) {
const re = e as RunError;
Deno.exit(re.code);
}
log.error(e);
Deno.exit(1);
}
}