From 3dc93acefe03af9bbe70f748e68a3f9352c63864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Cort=C3=B3n=20Cobas?= <104267232+carloscortonc@users.noreply.github.com> Date: Sun, 10 Mar 2024 09:51:44 +0100 Subject: [PATCH] feat: do not show `has-options` for autogenerated (#81) --- src/cli-utils.ts | 3 ++- test/cli-utils.test.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/cli-utils.ts b/src/cli-utils.ts index 851719b..4e70cf0 100644 --- a/src/cli-utils.ts +++ b/src/cli-utils.ts @@ -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 }); } diff --git a/test/cli-utils.test.ts b/test/cli-utils.test.ts index b702b18..ebb933c 100644 --- a/test/cli-utils.test.ts +++ b/test/cli-utils.test.ts @@ -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", () => {