forked from pkgxdev/pkgx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
50 lines (41 loc) · 959 Bytes
/
app.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
import useFlags, { useArgs } from "hooks/useFlags.ts"
import useMagic from "hooks/useMagic.ts"
import dump from "./app.dump.ts"
import exec from "./app.exec.ts"
import help from "./app.help.ts"
const rawArgs = useArgs(Deno.args)
const { silent, verbose, magic, verbosity } = useFlags()
if (verbose) {
const version = '0.1.0' //FIXME
console.log(`tea ${version}`)
}
console.debug({ rawArgs })
if (rawArgs.cd) {
const chdir = rawArgs.cd
console.verbose({ chdir })
Deno.chdir(chdir.string)
}
try {
const { mode, ...args } = await useMagic(rawArgs)
if (magic && (mode != 'help' || verbosity > 1)) {
const foo = { ...args, mode, chdir: rawArgs.cd }
console.verbose({"transformed-args": foo })
}
switch (mode) {
case "dump":
await dump(args)
break
case "exec":
await exec(args)
break
case "help":
await help()
break
}
} catch (err) {
if (silent) {
Deno.exit(1)
} else {
throw err
}
}