-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmod.ts
More file actions
69 lines (56 loc) · 1.72 KB
/
mod.ts
File metadata and controls
69 lines (56 loc) · 1.72 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
import type { CLIInfo } from './types/cli.d.ts'
import { PermsCheck } from './src/perms/check.ts'
import { cli } from './src/cli/mod.ts'
import { flagExtractor } from './src/utils/flag-extractor.ts'
import {
prefixLogError,
bgLogError
} from './src/cli/logging.ts'
await (async function main() {
//* Checking if there is any flag
if(!Deno.args || Deno.args.length === 0) {
bgLogError("You must provide at least one argument!", {
verbose: true
} as CLIInfo)
Deno.exit(1)
}
//* Extracting flags and command
const flags = flagExtractor(Deno.args)
if(flags.err) {
prefixLogError(`${flags.err}`, {
verbose: true
} as CLIInfo)
Deno.exit(1)
}
//* Checking if user want's to see extended verbose info
const verboseOn = flags.flags
?.find(flag => flag.flagName === 'verbose')?.flagValue as boolean ?? false
const cliInfo: CLIInfo = {
cmd: flags.cmd as string,
flags: flags.flags,
cwd: Deno.cwd(),
currDate: new Date(),
verbose: verboseOn
}
try {
//* Checking if script has right permissions to run
const permissions = await PermsCheck(cliInfo)
if(!permissions.success) {
prefixLogError(`${permissions.err}`, cliInfo)
Deno.exit(1)
}
//TODO Add OS check
//TODO Add version check and update recommendation
//* Actually running user's app
const cliStatus = await cli(cliInfo)
if(!cliStatus.success) {
prefixLogError(`${cliStatus.err}`, cliInfo)
Deno.exit(1)
}
//* Voila, finished!
Deno.exit(0)
} catch(error) {
prefixLogError(`[UNEXPECTED]\n ${error}`, cliInfo)
Deno.exit(1)
}
})()