mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-20 05:31:30 +00:00
refactor(cli): separate json payload output from logging
This commit is contained in:
@@ -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);
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user