From dea451a0d4499b6720ad813be6abb0c4d3f57b8d Mon Sep 17 00:00:00 2001 From: Damian Tarnacki Date: Sun, 17 May 2026 22:33:02 +0200 Subject: [PATCH] fix(cli): show help when no args are provided Print the root help output and exit successfully when the CLI is invoked without flags or commands. Add e2e coverage so the no-args behavior stays aligned with --help. --- src/index.ts | 5 +++++ tests/e2e/global-flags.test.ts | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/index.ts b/src/index.ts index 1c67deb..31e8de6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,6 +20,11 @@ cli.help(); cli.version(packageJson.version); try { + if (process.argv.slice(2).length === 0) { + cli.outputHelp(); + process.exit(0); + } + cli.parse(); } catch (err) { // CAC throws on unknown options / bad usage. Exit code 2 = USAGE per plan. diff --git a/tests/e2e/global-flags.test.ts b/tests/e2e/global-flags.test.ts index eb8d35a..fc70448 100644 --- a/tests/e2e/global-flags.test.ts +++ b/tests/e2e/global-flags.test.ts @@ -29,6 +29,17 @@ describe("e2e: global flags", () => { expect(output).toContain("doctor"); }); + it("no args exits 0 with command list", () => { + const result = runCli([]); + expect(result.exitCode).toBe(0); + const output = result.stdout + result.stderr; + expect(output).toContain("10x"); + expect(output).toContain("auth"); + expect(output).toContain("get"); + expect(output).toContain("list"); + expect(output).toContain("doctor"); + }); + it("unknown option on a command exits 2 with usage error", () => { const result = runCli(["auth", "--nonexistent-flag"]); expect(result.exitCode).toBe(2);