diff --git a/__tests__/e2e/cli/cli-args.e2e.test.ts b/__tests__/e2e/cli/cli-args.e2e.test.ts index 61a1421a..437ce798 100644 --- a/__tests__/e2e/cli/cli-args.e2e.test.ts +++ b/__tests__/e2e/cli/cli-args.e2e.test.ts @@ -152,6 +152,20 @@ describe("policies: list (default)", () => { expect(result.stdout).toContain("failproofai policies"); }); + it("accepts --no-color after the subcommand", () => { + const result = runCli("policies", "--no-color"); + assertSuccess(result); + expect(result.stdout).toContain("failproofai policies"); + expect(result.stdout).not.toMatch(/\x1B\[/); + }); + + it("accepts --no-color before the subcommand", () => { + const result = runCli("--no-color", "policies"); + assertSuccess(result); + expect(result.stdout).toContain("failproofai policies"); + expect(result.stdout).not.toMatch(/\x1B\[/); + }); + it("rejects unexpected positional argument", () => { const result = runCli("policies", "hi"); assertCleanError(result, "Unexpected argument: hi"); diff --git a/bin/failproofai.mjs b/bin/failproofai.mjs index 58415f53..edd66da8 100755 --- a/bin/failproofai.mjs +++ b/bin/failproofai.mjs @@ -6,6 +6,7 @@ * --hook Hook event from Claude Code (minimal startup latency) * --version / -v Print version and exit * --help / -h Show usage and exit + * --no-color Suppress ANSI color output * policies Manage policies (list / install / uninstall) * (default) Launch production dashboard */ @@ -34,6 +35,15 @@ if (!process.env.FAILPROOFAI_DIST_PATH) { const args = process.argv.slice(2); +// Global presentation flag: consume it before aliases, help routing, and +// subcommand validation so it works in any position. +if (args.includes("--no-color")) { + process.env.NO_COLOR = "1"; + for (let i = args.length - 1; i >= 0; i--) { + if (args[i] === "--no-color") args.splice(i, 1); + } +} + // ── one noun for policies ────────────────────────────────────────────────── // `policies`, `policy` and `pack` were three commands for one idea, two of them // a single letter apart and doing unrelated things. They are now three @@ -495,7 +505,7 @@ async function runCli() { ], footer: [ "failproofai [options] failproofai help for detail", - "docs.befailproof.ai discord.befailproof.ai -h this screen -v version", + "docs.befailproof.ai discord.befailproof.ai --no-color plain output -h help -v version", ], }); process.exit(0); @@ -1808,6 +1818,7 @@ async function runCli() { ["--scope ", "user, project or local. Default: user. --uninstall also takes all."], ["--beta", "Include beta policies. On --uninstall, only those."], ["--custom, -c ", "Custom policy file; repeat for several. Bare on --uninstall, clears every explicit path."], + ["--no-color", "Suppress ANSI color output; the same as NO_COLOR=1."], ], }, {