Skip to content

Commit

Permalink
feat: do not show has-options for autogenerated (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
carloscortonc committed Mar 10, 2024
1 parent 4654dba commit 3dc93ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cli-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ export function generateScopedHelp(
(acc, curr) => {
const { kind, positional, required, key } = curr;
if (kind === Kind.OPTION) {
acc.hasOptions = true;
// Ignore autoincluded options when rendering `has-options` string
acc.hasOptions ||= !(["help", "version"] as const).some((k) => k === key && cliOptions[k].autoInclude);
if (positional === true || typeof positional === "number") {
acc.positionalOptions.push({ index: positional, key, required });
}
Expand Down
18 changes: 18 additions & 0 deletions test/cli-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,24 @@ Options:
-g, --global Option shared between all commands (default: "globalvalue")
-h, --help Display global help, or scoped to a namespace/command
`);
});
it("Only autoincluded options: [OPTIONS] is not included", () => {
let output = "";
logger.mockImplementation((m: any) => !!(output += m));
const noOptsDef = { nms: { options: { cmd: { options: { opt: {} } } } } };
generateScopedHelp(new Cli(noOptsDef).definition, [], cliOptions);
expect(output).toBe(`
Usage: cli-name NAMESPACE
cli-description
Namespaces:
nms -
Options:
-h, --help Display global help, or scoped to a namespace/command
`);
});
it("With location", () => {
Expand Down

0 comments on commit 3dc93ac

Please sign in to comment.