-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ts
More file actions
52 lines (45 loc) · 1.58 KB
/
Copy pathtest.ts
File metadata and controls
52 lines (45 loc) · 1.58 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
import type { Command } from "commander";
import chalk from "chalk";
export function customHelp(program: Command): string {
const lines: string[] = [];
lines.push("");
lines.push(chalk.bold("用法:"));
lines.push(
` ${chalk.cyan("dskcode")} ${chalk.dim("[global-options]")} ${chalk.green("<command>")} ${chalk.dim("[options]")}`,
);
lines.push("");
const globalOpts = program.options.filter(
(o) => o.long !== "--help" && o.long !== "--version" && o.long !== "--config",
);
if (globalOpts.length > 0) {
lines.push(chalk.bold("全局选项:"));
for (const opt of globalOpts) {
const flags = [opt.short, opt.long].filter(Boolean).join(", ");
lines.push(` ${chalk.cyan(flags.padEnd(24))} ${opt.description ?? ""}`);
}
lines.push("");
}
lines.push(chalk.bold("内置选项:"));
for (const flag of ["-h, --help", "-V, --version"]) {
const opt = program.options.find(
(o) => o.long === (flag.includes("help") ? "--help" : "--version"),
);
if (opt) {
lines.push(` ${chalk.cyan(flag.padEnd(24))} ${opt.description ?? ""}`);
}
}
lines.push("");
const cmds = program.commands.filter((c) => !c.name().startsWith("help"));
if (cmds.length > 0) {
lines.push(chalk.bold("命令:"));
for (const cmd of cmds) {
lines.push(` ${chalk.green(cmd.name().padEnd(24))} ${cmd.description()}`);
}
lines.push("");
}
lines.push(chalk.bold("示例:"));
lines.push(` ${chalk.dim("# 启动交互式对话(无参默认行为)")}`);
lines.push(" dskcode");
lines.push("");
return lines.join("\n");
}