Skip to content

Commit 302969c

Browse files
committed
fix(plugin-help): should display root commands in alias correctly
1 parent 2d59c94 commit 302969c

3 files changed

Lines changed: 141 additions & 1 deletion

File tree

packages/plugin-help/src/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export class HelpRenderer {
288288
formatCommandName(command.name.slice(prefix.length)),
289289
);
290290
const aliases = command.alias
291-
? ` (${toArray(command.alias).join(", ")})`
291+
? ` (${toArray(command.alias).map(formatCommandName).join(", ")})`
292292
: "";
293293
const item = [`${commandName}${aliases}`, command.description].filter(
294294
isTruthy,

packages/plugin-help/test/__snapshots__/plugin-help.test.ts.snap

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,88 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`plugin-help > alias > should show alias for subcommands 1`] = `
4+
[
5+
[
6+
"test parent not found
7+
8+
Available Subcommands
9+
child (c) Child command",
10+
],
11+
]
12+
`;
13+
14+
exports[`plugin-help > alias > should show array of aliases 1`] = `
15+
[
16+
[
17+
"test v0.0.0 - test
18+
19+
Usage
20+
$ test <command> [flags]
21+
22+
Global Flags
23+
--help, -h Boolean Show help [default: false]
24+
25+
Commands
26+
help Show help
27+
test (t, test-cmd) Test command",
28+
],
29+
]
30+
`;
31+
32+
exports[`plugin-help > alias > should show root alias (empty string in array) 1`] = `
33+
[
34+
[
35+
"test v0.0.0 - test
36+
37+
Usage
38+
$ test [command] [flags]
39+
40+
Global Flags
41+
--help, -h Boolean Show help [default: false]
42+
43+
Commands
44+
help Show help
45+
test (t, (root)) Test command",
46+
],
47+
]
48+
`;
49+
50+
exports[`plugin-help > alias > should show root alias (empty string) 1`] = `
51+
[
52+
[
53+
"test v0.0.0 - test
54+
55+
Usage
56+
$ test [command] [flags]
57+
58+
Global Flags
59+
--help, -h Boolean Show help [default: false]
60+
61+
Commands
62+
help Show help
63+
test Test command",
64+
],
65+
]
66+
`;
67+
68+
exports[`plugin-help > alias > should show single string alias 1`] = `
69+
[
70+
[
71+
"test v0.0.0 - test
72+
73+
Usage
74+
$ test <command> [flags]
75+
76+
Global Flags
77+
--help, -h Boolean Show help [default: false]
78+
79+
Commands
80+
help Show help
81+
test (t) Test command",
82+
],
83+
]
84+
`;
85+
386
exports[`plugin-help > grouping > should display subcommands 1`] = `
487
[
588
[

packages/plugin-help/test/plugin-help.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,4 +670,61 @@ describe("plugin-help", () => {
670670
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
671671
});
672672
});
673+
674+
describe("alias", () => {
675+
it("should show single string alias", () => {
676+
TestBaseCli()
677+
.use(helpPlugin())
678+
.command("test", "Test command", {
679+
alias: "t",
680+
})
681+
.parse(["help"]);
682+
683+
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
684+
});
685+
686+
it("should show array of aliases", () => {
687+
TestBaseCli()
688+
.use(helpPlugin())
689+
.command("test", "Test command", {
690+
alias: ["t", "test-cmd"],
691+
})
692+
.parse(["help"]);
693+
694+
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
695+
});
696+
697+
it("should show root alias (empty string)", () => {
698+
TestBaseCli()
699+
.use(helpPlugin())
700+
.command("test", "Test command", {
701+
alias: "",
702+
})
703+
.parse(["help"]);
704+
705+
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
706+
});
707+
708+
it("should show root alias (empty string in array)", () => {
709+
TestBaseCli()
710+
.use(helpPlugin())
711+
.command("test", "Test command", {
712+
alias: ["t", ""],
713+
})
714+
.parse(["help"]);
715+
716+
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
717+
});
718+
719+
it("should show alias for subcommands", () => {
720+
TestBaseCli()
721+
.use(helpPlugin())
722+
.command("parent child", "Child command", {
723+
alias: "c",
724+
})
725+
.parse(["parent", "--help"]);
726+
727+
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
728+
});
729+
});
673730
});

0 commit comments

Comments
 (0)