Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/global-flags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down