Skip to content
Closed
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
8 changes: 4 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ export async function main(argv: string[]): Promise<number> {
const args = parseArgs(argv);
const { command, flags } = args;

if (flags["help"] || command === "help" || command === undefined) {
process.stdout.write(usage());
return command === undefined && !flags["help"] ? 2 : 0;
}
if (flags["version"]) {
process.stdout.write(`${VERSION}\n`);
return 0;
}
if (flags["help"] || command === "help" || command === undefined) {
process.stdout.write(usage());
return command === undefined && !flags["help"] ? 2 : 0;
}
if (command === "rules") {
printRules();
return 0;
Expand Down
31 changes: 29 additions & 2 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
import { describe, expect, it } from "vitest";
import { collectHeaders, parseArgs } from "../src/cli.js";
import { afterEach, describe, expect, it, vi } from "vitest";
import { collectHeaders, main, parseArgs } from "../src/cli.js";

afterEach(() => {
vi.restoreAllMocks();
});

describe("top-level information flags", () => {
it("prints the version and succeeds without a positional command", async () => {
const write = vi.spyOn(process.stdout, "write").mockImplementation(() => true);

await expect(main(["--version"])).resolves.toBe(0);

expect(write).toHaveBeenCalledOnce();
expect(write).toHaveBeenCalledWith(expect.stringMatching(/^\d+\.\d+\.\d+\n$/));
});

it("keeps bare invocation as a usage error", async () => {
vi.spyOn(process.stdout, "write").mockImplementation(() => true);

await expect(main([])).resolves.toBe(2);
});

it("keeps explicit help successful", async () => {
vi.spyOn(process.stdout, "write").mockImplementation(() => true);

await expect(main(["--help"])).resolves.toBe(0);
});
});

describe("HTTP headers", () => {
it("collects every repeated --header flag", () => {
Expand Down
Loading