Skip to content

Commit 83ae9ec

Browse files
committed
🐛 fix(plugin-help): wrongly merged pr
1 parent 10b7936 commit 83ae9ec

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed

packages/plugin-help/src/index.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { HandlerContext, RootType } from "@clerc/core";
22
import { NoSuchCommandError, Root, definePlugin, formatCommandName, resolveCommandStrict, withBrackets } from "@clerc/core";
3-
import { toArray } from "@clerc/utils";
3+
import { gracefulFlagName, toArray } from "@clerc/utils";
44
import pc from "picocolors";
55

66
import type { Render, Renderers, Section } from "./renderer";
@@ -95,7 +95,22 @@ const generateSubcommandHelp = (render: Render, ctx: HandlerContext, command: st
9595
if (subcommand.flags) {
9696
sections.push({
9797
title: t("help.flags")!,
98-
body: splitTable(formatFlags(subcommand.flags)),
98+
body: splitTable(
99+
Object.entries(subcommand.flags).map(([name, flag]) => {
100+
const hasDefault = flag.default !== undefined;
101+
let flagNameWithAlias: string[] = [gracefulFlagName(name)];
102+
if (flag.alias) {
103+
flagNameWithAlias.push(gracefulFlagName(flag.alias));
104+
}
105+
flagNameWithAlias = flagNameWithAlias.map(renderers.renderFlagName);
106+
const items = [pc.blue(flagNameWithAlias.join(", ")), renderers.renderType(flag.type, hasDefault)];
107+
items.push(DELIMITER, flag.description || t("help.noDescription")!);
108+
if (hasDefault) {
109+
items.push(`(${t("help.default", renderers.renderDefault(flag.default))})`);
110+
}
111+
return items;
112+
}),
113+
),
99114
});
100115
}
101116
if (subcommand.notes) {
@@ -157,7 +172,7 @@ export const helpPlugin = ({
157172
};
158173

159174
if (command) {
160-
cli = cli.command("help", t("help.helpDdescription")!, {
175+
cli = cli.command("help", t("help.comamndDescription")!, {
161176
parameters: [
162177
"[command...]",
163178
],
@@ -182,7 +197,7 @@ export const helpPlugin = ({
182197
}
183198

184199
if (flag) {
185-
cli = cli.flag("help", t("help.helpDdescription")!, {
200+
cli = cli.flag("help", t("help.commandDescription")!, {
186201
alias: "h",
187202
type: Boolean,
188203
default: false,

packages/plugin-help/src/locales.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,37 @@ import type { Locales } from "@clerc/core";
22

33
export const locales: Locales = {
44
"en": {
5-
"help.name": "Name",
6-
"help.version": "Version",
7-
"help.subcommand": "Subcommand",
8-
"help.commands": "Commands",
9-
"help.globalFlags": "Global Flags",
10-
"help.flags": "Flags",
11-
"help.description": "Description",
12-
"help.usage": "Usage",
13-
"help.examples": "Examples",
14-
"help.notes": "Notes",
5+
"help.name": "Name:",
6+
"help.version": "Version:",
7+
"help.subcommand": "Subcommand:",
8+
"help.commands": "Commands:",
9+
"help.globalFlags": "Global Flags:",
10+
"help.flags": "Flags:",
11+
"help.description": "Description:",
12+
"help.usage": "Usage:",
13+
"help.examples": "Examples:",
14+
"help.notes": "Notes:",
15+
"help.noDescription": "(No description)",
1516
"help.notes.1": "If no command is specified, show help for the CLI.",
1617
"help.notes.2": "If a command is specified, show help for the command.",
1718
"help.notes.3": "-h is an alias for --help.",
1819
"help.examples.1": "Show help",
1920
"help.examples.2": "Show help for a specific command",
2021
"help.commandDescription": "Show help",
21-
"help.default": "Default: ",
22+
"help.default": "Default: %s",
2223
},
2324
"zh-CN": {
24-
"help.name": "名称",
25-
"help.version": "版本",
26-
"help.subcommand": "子命令",
27-
"help.commands": "命令",
28-
"help.globalFlags": "全局标志",
29-
"help.flags": "标志",
30-
"help.description": "描述",
31-
"help.usage": "使用",
32-
"help.examples": "示例",
33-
"help.notes": "备注",
25+
"help.name": "名称:",
26+
"help.version": "版本:",
27+
"help.subcommand": "子命令:",
28+
"help.commands": "命令:",
29+
"help.globalFlags": "全局标志:",
30+
"help.flags": "标志:",
31+
"help.description": "描述:",
32+
"help.usage": "使用:",
33+
"help.examples": "示例:",
34+
"help.notes": "备注:",
35+
"help.noDescription": "(无描述)",
3436
"help.notes.1": "如果没有指定展示哪个命令的帮助信息,默认展示CLI的。",
3537
"help.notes.2": "如果指定了则展示该命令帮助信息。",
3638
"help.notes.3": "-h 是 --help 的一个别名。",

packages/plugin-help/src/renderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ export const render: Render = (sections: Section[]) => {
3434
.map(line => indent + line);
3535
formattedBody.unshift("");
3636
const body = formattedBody.join("\n");
37-
rendered.push(table([[pc.bold(`${section.title}:`)], [body]]).toString());
37+
rendered.push(table([[pc.bold(`${section.title}`)], [body]]).toString());
3838
} else if (section.type === "inline") {
3939
const formattedBody = section.items
40-
.map(item => [pc.bold(`${item.title}:`), item.body]);
40+
.map(item => [pc.bold(`${item.title}`), item.body]);
4141
const tableGenerated = table(formattedBody);
4242
rendered.push(tableGenerated.toString());
4343
}

0 commit comments

Comments
 (0)