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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ coverage/
.dolt/
*.db
.beads-credential-key
AGY.md
32 changes: 0 additions & 32 deletions plan.md

This file was deleted.

31 changes: 31 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const args = process.argv.slice(2);

// Check if any argument is empty or blank
if (args.some(arg => arg.trim() === '')) {
console.error("Error: Arguments cannot be empty or blank strings.");
process.exit(1);
}

if (args.includes('--version') || args.includes('-v')) {
console.log("fleet-e2e-toy v1.0.0");
process.exit(0);
}

if (args.includes('--help') || args.includes('-h') || args.includes('help')) {
console.log(`Usage: fleet-e2e-toy [options] [command]

Options:
-v, --version Show version number
-h, --help Show help

Commands:
help Show help`);
process.exit(0);
}

// Reject unknown commands or flags
if (args.length > 0) {
console.error(`Unknown command or flag: ${args[0]}`);
process.exit(1);
}

68 changes: 68 additions & 0 deletions tests/cli.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { spawnSync } from "child_process";
import * as path from "path";

describe("CLI Tests", () => {
const runCLI = (args: string[]) => {
const cliPath = path.resolve(__dirname, "../src/cli.ts");

const result = spawnSync("node", ["-r", "ts-node/register", cliPath, ...args], {
encoding: "utf8",
});

return {
stdout: result.stdout || "",
stderr: result.stderr || "",
status: result.status,
};
};

it("prints version with --version flag", () => {
const { stdout, status } = runCLI(["--version"]);
expect(status).toBe(0);
expect(stdout.trim()).toBe("fleet-e2e-toy v1.0.0");
});

it("prints version with -v flag", () => {
const { stdout, status } = runCLI(["-v"]);
expect(status).toBe(0);
expect(stdout.trim()).toBe("fleet-e2e-toy v1.0.0");
});

it("prints usage with help subcommand", () => {
const { stdout, status } = runCLI(["help"]);
expect(status).toBe(0);
expect(stdout).toContain("Usage: fleet-e2e-toy");
expect(stdout).toContain("Options:");
expect(stdout).toContain("Commands:");
});

it("prints usage with --help flag", () => {
const { stdout, status } = runCLI(["--help"]);
expect(status).toBe(0);
expect(stdout).toContain("Usage: fleet-e2e-toy");
});

it("prints usage with -h flag", () => {
const { stdout, status } = runCLI(["-h"]);
expect(status).toBe(0);
expect(stdout).toContain("Usage: fleet-e2e-toy");
});

it("rejects empty string argument", () => {
const { stderr, status } = runCLI([""]);
expect(status).toBe(1);
expect(stderr.trim()).toContain("Error: Arguments cannot be empty or blank strings.");
});

it("rejects blank string argument", () => {
const { stderr, status } = runCLI([" "]);
expect(status).toBe(1);
expect(stderr.trim()).toContain("Error: Arguments cannot be empty or blank strings.");
});

it("rejects unknown command", () => {
const { stderr, status } = runCLI(["unknown_command"]);
expect(status).toBe(1);
expect(stderr.trim()).toContain("Unknown command or flag: unknown_command");
});
});
2 changes: 2 additions & 0 deletions tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
npx ts-node src/cli.ts "$@"
2 changes: 2 additions & 0 deletions tool.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
npx ts-node src/cli.ts %*
Loading