-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.ts
More file actions
62 lines (60 loc) · 1.39 KB
/
main.ts
File metadata and controls
62 lines (60 loc) · 1.39 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
import { brightRed } from "@std/fmt/colors";
import yargs, { YargsInstance } from "yargs";
import { version } from "./src/info.ts";
import {
cmp,
eq,
get,
gt,
gte,
inc,
lt,
lte,
parse,
set,
sort,
} from "./src/commands/mod.ts";
import { getContext } from "./src/context.ts";
import { ApplicationError } from "./src/errors/application.error.ts";
const args = Deno.args
.filter((arg) => arg?.trim())
.filter((arg) => arg !== "--");
try {
const context = getContext();
await yargs()
.scriptName("semver")
.command(get)
.command(set)
.command(inc)
.command(parse)
.command(cmp)
.command(gt)
.command(gte)
.command(lt)
.command(lte)
.command(eq)
.command(sort)
.strictOptions()
.strictCommands()
.demandCommand(1)
.version(version)
.fail((msg: string, _err: unknown, _yargs: YargsInstance) => {
if (msg) {
console.error(`${brightRed("error")}: ${msg}`);
Deno.exit(1);
}
})
.parse(args, context);
} catch (error) {
if (error instanceof TypeError) {
console.error(`${brightRed("error")}: ${error.message}`);
Deno.exit(1);
} else if (error instanceof ApplicationError) {
const { exitCode, code, message, name } = error;
console.error(`${brightRed("error")}: ${name} ${code} ${message}`);
Deno.exit(exitCode);
} else {
console.error(error);
Deno.exit(1);
}
}