Skip to content

Commit 4c25ef3

Browse files
committed
fix(plugin-help): should not show command placeholder when no command exists
1 parent b7b69e5 commit 4c25ef3

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

packages/plugin-help/src/renderer.ts

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

179181
if (

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,28 @@ exports[`plugin-help > should format custom flag type with "display" property 1`
200200
]
201201
`;
202202
203+
exports[`plugin-help > should not show commands placeholder when no commands exist 1`] = `
204+
[
205+
[
206+
"test v0.0.0 - test
207+
208+
Usage
209+
$ test [flags]
210+
211+
Global Flags
212+
--help, -h Boolean Show help [default: false]
213+
214+
Examples
215+
$ test <command> --help - Show help for a specific command
216+
217+
Notes
218+
If no command is specified, show help for the CLI.
219+
If a command is specified, show help for the command.
220+
-h is an alias for --help.",
221+
],
222+
]
223+
`;
224+
203225
exports[`plugin-help > should not show commands which set \`show\` to false 1`] = `
204226
[
205227
[

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ describe("plugin-help", () => {
142142
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
143143
});
144144

145+
it("should not show commands placeholder when no commands exist", () => {
146+
TestBaseCli()
147+
.use(helpPlugin({ command: false }))
148+
.parse(["--help"]);
149+
150+
expect(getConsoleMock("log").mock.calls).toMatchSnapshot();
151+
});
152+
145153
it("should not show commands which set `show` to false", () => {
146154
TestBaseCli()
147155
.use(helpPlugin())

0 commit comments

Comments
 (0)