-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
executable file
·132 lines (117 loc) · 3.11 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bun
import pkg from "./package.json";
import PMB from "./src/cli/pmb";
import { L } from "./src/shared/utils";
import { Command } from "commander";
import { useI18n } from "./src/i18n";
const pmb = new PMB();
const program = new Command();
const { t } = await useI18n();
L.Logo();
program.name("PMB").description(t("cli.pmb.description")).version(pkg.version);
program
.command("start")
.description(t("cli.start.description"))
.argument("<entry>", t("cli.start.entry"))
.option("-n, --name <process-name>", t("cli.start.name"))
.option("-s, --starter <starter-program>", t("cli.start.starter"))
.option("-a, --args <starter-program-args>", t("cli.start.starterArgs"))
.action((entry, options) => {
pmb.start(entry, options?.name, options?.starter, options?.args);
});
program
.command("restart")
.description(t("cli.restart.description"))
.argument("<name-or-pid>", t("cli.restart.nameOrPid"))
.option("-r, --reset [rest-restart-count]", t("cli.restart.reset"))
.action((value, { reset }) => {
let restart: number | boolean | undefined = void 0;
if (reset) {
if (typeof reset === "boolean") {
restart = reset;
} else if (typeof reset === "string" && /\d+/.test(reset)) {
const count = parseInt(reset);
if (count >= 0) {
restart = count;
}
}
}
if (isNaN(value)) {
pmb.restart("name", value, restart);
} else {
pmb.restart("pid", value, restart);
}
});
program
.command("stop")
.description(t("cli.stop.description"))
.argument("<name-or-pid>", t("cli.stop.nameOrPid"))
.action((value) => {
if (isNaN(value)) {
pmb.stop("name", value);
} else {
pmb.stop("pid", value);
}
});
program
.command("rm")
.description(t("cli.rm.description"))
.argument("<name-or-pid>", t("cli.rm.nameOrPid"))
.action((value) => {
if (isNaN(value)) {
pmb.rm("name", value);
} else {
pmb.rm("pid", value);
}
});
program
.command("log")
.description(t("cli.log.description"))
.argument("[name-or-pid]", t("cli.log.description"))
.action((value) => {
if (!isNaN(value)) {
pmb.log("pid", value);
return;
}
pmb.log("name", value);
});
program
.command("ls")
.description(t("cli.ls.description"))
.action(() => {
pmb.list();
});
program
.command("monit")
.description(t("cli.monit.description"))
.action(() => {
pmb.monit();
});
program
.command("daemon")
.description(t("cli.daemon.description"))
.argument("<action>", t("cli.daemon.action"))
.action((actions) => {
pmb.daemon(actions);
});
program
.command("ui")
.description(t("cli.ui.description"))
.option("-e, --enabled", t("cli.ui.enabled"))
.option("-d, --disabled", t("cli.ui.disabled"))
.action(({ enabled, disabled }) => {
pmb.ui(enabled ? true : disabled ? false : void 0);
});
program
.command("lang")
.description(t("cli.lang.description"))
.action(() => {
pmb.setLang();
});
program
.command("upgrade")
.description(t("cli.upgrade.description"))
.action(() => {
pmb.upgrade(pkg.version);
});
program.parse();