Skip to content

Commit d694758

Browse files
committed
fix(plugin-help): should not show command placeholder when only registered root command
1 parent 4c25ef3 commit d694758

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

packages/plugin-help/src/renderer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ export class HelpRenderer {
173173
usage += ` ${command.parameters.map((p) => (typeof p === "string" ? p : p.key)).join(" ")}`;
174174
}
175175
} else {
176-
if (this._cli._commands.size > 0) {
176+
if (
177+
this._cli._commands.size > 0 &&
178+
!(this._cli._commands.has("") && this._cli._commands.size === 1)
179+
) {
177180
usage += this._cli._commands.has("") ? " [command]" : " <command>";
178181
}
179182
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,34 @@ exports[`plugin-help > should not show commands placeholder when no commands exi
222222
]
223223
`;
224224
225+
exports[`plugin-help > should not show commands placeholder when no commands exist 2`] = `
226+
[
227+
[
228+
"test
229+
230+
Usage
231+
$ test [flags]
232+
233+
Global Flags
234+
--help, -h Boolean Show help [default: false]",
235+
],
236+
]
237+
`;
238+
239+
exports[`plugin-help > should not show commands placeholder when only registered root command 1`] = `
240+
[
241+
[
242+
"test
243+
244+
Usage
245+
$ test [flags]
246+
247+
Global Flags
248+
--help, -h Boolean Show help [default: false]",
249+
],
250+
]
251+
`;
252+
225253
exports[`plugin-help > should not show commands which set \`show\` to false 1`] = `
226254
[
227255
[

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ describe("plugin-help", () => {
150150
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
151151
});
152152

153+
it("should not show commands placeholder when only registered root command", () => {
154+
TestBaseCli()
155+
.use(helpPlugin({ command: false }))
156+
.command("")
157+
.parse(["--help"]);
158+
159+
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
160+
});
161+
153162
it("should not show commands which set `show` to false", () => {
154163
TestBaseCli()
155164
.use(helpPlugin())

0 commit comments

Comments
 (0)