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);