-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
59 lines (51 loc) · 1.44 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
import { helpers, termost } from "termost";
type ProgramContext = {
globalFlag: boolean;
};
const program = termost<ProgramContext>(
"Example to showcase the `command` API",
);
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`);
helpers.message(`👉 Shared global flag = ${globalFlag}`);
helpers.message(`👉 Local command flag = ${localFlag}`);
helpers.message(`👉 Context value = ${JSON.stringify(context)}`);
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)}`);
},
});