-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
71 lines (62 loc) · 1.69 KB
/
index.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
import { helpers, termost } from "termost";
import { name, version } from "../package.json" with { type: "json" };
type ProgramContext = {
globalFlag: boolean;
};
const program = termost<ProgramContext>({
name,
description: "Example to showcase the `command` API",
version,
});
program.option({
key: "globalFlag",
name: "global",
description: "Shared flag between commands",
defaultValue: false,
});
type BuildCommandContext = {
localFlag: string;
};
program
.command<BuildCommandContext>({
name: "build",
description: "Transpile and bundle in production mode",
})
.option({
key: "localFlag",
name: "local",
description: "Local command flag",
defaultValue: "local-value",
})
.task({
handler(context, argv) {
const { globalFlag, localFlag } = context;
helpers.message(`👋 Hello, I'm the ${argv.command} command`, {
lineBreak: { end: true, start: false },
});
helpers.message(`👉 Shared global flag = ${globalFlag}`, {
label: false,
});
helpers.message(`👉 Local command flag = ${localFlag}`, {
lineBreak: true,
});
helpers.message(`👉 Context value = ${JSON.stringify(context)}`, {
lineBreak: { end: true, start: true },
});
helpers.message(`👉 Argv value = ${JSON.stringify(argv)}`);
},
});
program
.command({
name: "watch",
description: "Rebuild your assets on any code change",
})
.task({
handler(context, argv) {
const { globalFlag } = context;
helpers.message(`👋 Hello, I'm the ${argv.command} command`);
helpers.message(`👉 Shared global flag = ${globalFlag}`);
helpers.message(`👉 Context value = ${JSON.stringify(context)}`);
helpers.message(`👉 Argv value = ${JSON.stringify(argv)}`);
},
});