forked from pkgxdev/pkgx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.ts
77 lines (67 loc) · 2.47 KB
/
entrypoint.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
/*
this file seeks to be the only file that is “impure”
ie. using the global environment to affect the program
*/
import { render as perror } from "./src/err-handler.ts"
import { setColorEnabled } from "deno/fmt/colors.ts"
import clicolor from "./src/utils/clicolor.ts"
setColorEnabled(clicolor(Deno.stderr.rid))
///////////////////////////////////////////////////////// backwards compatability
const argstr = Deno.args.join(' ')
if (/--hook(=[a-z]+)?/.test(argstr) || argstr == '--env --keep-going --silent --dry-run=w/trace' || argstr == '-Eds' || argstr.endsWith("/magic -Esk --chaste env")) {
perror('deprecated', 'magic', [
['type `pkgx integrate --dry-run` to use our new integrations']
], 'https://blog.pkgx.sh/v1')
}
if (parseInt(Deno.env.get("PKGX_LVL")!) >= 10) {
perror('fatal', 'PKGX_LVL >= 10', [], 'https://github.com/orgs/pkgxdev/discussions/11')
Deno.exit(2)
}
if (argstr == '--prefix') {
console.error("%cdeprecated: %cuse ${PKGX_DIR:-$HOME/.pkgx} instead", 'color: red', 'color: initial')
console.log(Deno.env.get("PKGX_DIR") || Deno.env.get("HOME") + "/.pkgx")
Deno.exit(0)
}
if (argstr == 'install' || argstr == 'unload') {
console.error('pkgx: error: shellcode not loaded')
console.error('pkgx: ^^run: eval "$(pkgx integrate)"')
Deno.exit(1)
}
//////////////////////////////////////////////////////////////////////////// main
import err_handler from "./src/err-handler.ts"
import parse_args from "./src/parse-args.ts"
import { isNumber } from "is-what"
import app from "./src/app.ts"
import { utils } from "pkgx"
const { flatmap } = utils
try {
const args = parse_args(Deno.args)
if (args.flags.verbosity === undefined) {
let shv: number | undefined
if (Deno.env.get("DEBUG")) {
args.flags.verbosity = 2
} else if ((shv = flatmap(Deno.env.get("VERBOSE"), parseInt)) && isNumber(shv)) {
args.flags.verbosity = shv
} else if (Deno.env.get("CI")) {
args.flags.verbosity = -1 // quieter but not silent
} else {
args.flags.verbosity = 0
}
}
if (args.flags.verbosity <= -2) {
console.log = () => {}
console.error = () => {}
}
//FIXME ⌄⌄ can’t figure this out
// deno-lint-ignore no-explicit-any
await app(args as any, logger_prefix())
} catch (err) {
const code = err_handler(err)
Deno.exit(code)
}
/////////////////////////////////////////////////////////////////////////// utils
function logger_prefix() {
if (Deno.env.get("CI") || !Deno.isatty(Deno.stdin.rid)) {
return 'pkgx'
}
}