refactor(cli): separate json payload output from logging

This commit is contained in:
Peter Steinberger
2026-03-22 23:19:14 +00:00
parent 274af0486a
commit 4ee41cc6f3
89 changed files with 710 additions and 693 deletions

View File

@@ -145,6 +145,14 @@ function exitHooksCliWithError(err: unknown): never {
process.exit(1);
}
function writeHooksOutput(value: string, json: boolean | undefined): void {
if (json) {
defaultRuntime.writeStdout(value);
return;
}
defaultRuntime.log(value);
}
async function runHooksCliAction(action: () => Promise<void> | void): Promise<void> {
try {
await action();
@@ -455,7 +463,7 @@ export function registerHooksCli(program: Command): void {
runHooksCliAction(async () => {
const config = loadConfig();
const report = buildHooksReport(config);
defaultRuntime.log(formatHooksList(report, opts));
writeHooksOutput(formatHooksList(report, opts), opts.json);
}),
);
@@ -467,7 +475,7 @@ export function registerHooksCli(program: Command): void {
runHooksCliAction(async () => {
const config = loadConfig();
const report = buildHooksReport(config);
defaultRuntime.log(formatHookInfo(report, name, opts));
writeHooksOutput(formatHookInfo(report, name, opts), opts.json);
}),
);
@@ -479,7 +487,7 @@ export function registerHooksCli(program: Command): void {
runHooksCliAction(async () => {
const config = loadConfig();
const report = buildHooksReport(config);
defaultRuntime.log(formatHooksCheck(report, opts));
writeHooksOutput(formatHooksCheck(report, opts), opts.json);
}),
);