fix(cli): return nonzero status for operation failures (#121)

This commit is contained in:
morluto authored and GitHub committed 2026-07-14 06:33:34 +08:00
1 parent 73852202d4
commit 00c187e32b
9 files changed
+207 -55

No files matched your search

+3 -21
View File
@@ -1,26 +1,12 @@
import { Cli, Errors, z } from "incur";
import { Cli, z } from "incur";
import {
captureProcessScenarioFile,
compareProcessEvidenceFiles,
isProcessCliErrorOutput,
} from "./application/ProcessCli.js";
import { logCliCommand } from "./cliLogging.js";
import type { Logger } from "./logger.js";
const requireProcessCommandSuccess = async <Value>(
execute: () => Promise<Value>,
): Promise<Value> => {
const value = await execute();
if (isProcessCliErrorOutput(value))
throw new Errors.IncurError({
code: "PROCESS_COMMAND_FAILED",
message: value.message,
retryable: false,
});
return value;
};
/** Register Process Capture v4 one-shot commands through shared application services. */
export const registerProcessCommands = (
cli: ReturnType<typeof Cli.create>,
@@ -31,9 +17,7 @@ export const registerProcessCommands = (
args: z.object({ scenario: z.string().describe("Scenario JSON path") }),
run: ({ args }) =>
logCliCommand(logger, "capture-process", () =>
requireProcessCommandSuccess(() =>
captureProcessScenarioFile(args.scenario),
),
captureProcessScenarioFile(args.scenario),
),
});
cli.command("compare-process-captures", {
@@ -44,9 +28,7 @@ export const registerProcessCommands = (
}),
run: ({ args }) =>
logCliCommand(logger, "compare-process-captures", () =>
requireProcessCommandSuccess(() =>
compareProcessEvidenceFiles(args.left, args.right),
),
compareProcessEvidenceFiles(args.left, args.right),
),
});
};