mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-23 23:22:32 +00:00
refactor(cli): separate json payload output from logging
This commit is contained in:
@@ -124,14 +124,14 @@ export function registerGatewayCli(program: Command) {
|
||||
const params = JSON.parse(String(opts.params ?? "{}"));
|
||||
const result = await callGatewayCli(method, { ...rpcOpts, config }, params);
|
||||
if (rpcOpts.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
defaultRuntime.writeJson(result);
|
||||
return;
|
||||
}
|
||||
const rich = isRich();
|
||||
defaultRuntime.log(
|
||||
`${colorize(rich, theme.heading, "Gateway call")}: ${colorize(rich, theme.muted, String(method))}`,
|
||||
);
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
defaultRuntime.writeJson(result);
|
||||
}, "Gateway call failed");
|
||||
}),
|
||||
);
|
||||
@@ -148,7 +148,7 @@ export function registerGatewayCli(program: Command) {
|
||||
const config = await readBestEffortConfig();
|
||||
const result = await callGatewayCli("usage.cost", { ...rpcOpts, config }, { days });
|
||||
if (rpcOpts.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
defaultRuntime.writeJson(result);
|
||||
return;
|
||||
}
|
||||
const rich = isRich();
|
||||
@@ -170,7 +170,7 @@ export function registerGatewayCli(program: Command) {
|
||||
const config = await readBestEffortConfig();
|
||||
const result = await callGatewayCli("health", { ...rpcOpts, config });
|
||||
if (rpcOpts.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
defaultRuntime.writeJson(result);
|
||||
return;
|
||||
}
|
||||
const rich = isRich();
|
||||
@@ -242,18 +242,12 @@ export function registerGatewayCli(program: Command) {
|
||||
const port = pickGatewayPort(b);
|
||||
return { ...b, wsUrl: host ? `ws://${host}:${port}` : null };
|
||||
});
|
||||
defaultRuntime.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
timeoutMs,
|
||||
domains,
|
||||
count: enriched.length,
|
||||
beacons: enriched,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
defaultRuntime.writeJson({
|
||||
timeoutMs,
|
||||
domains,
|
||||
count: enriched.length,
|
||||
beacons: enriched,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
waitForActiveTasks,
|
||||
} from "../../process/command-queue.js";
|
||||
import { createRestartIterationHook } from "../../process/restart-recovery.js";
|
||||
import type { defaultRuntime } from "../../runtime.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
|
||||
const gatewayLog = createSubsystemLogger("gateway");
|
||||
|
||||
@@ -28,7 +28,7 @@ type GatewayRunSignalAction = "stop" | "restart";
|
||||
|
||||
export async function runGatewayLoop(params: {
|
||||
start: () => Promise<Awaited<ReturnType<typeof startGatewayServer>>>;
|
||||
runtime: typeof defaultRuntime;
|
||||
runtime: RuntimeEnv;
|
||||
lockPort?: number;
|
||||
}) {
|
||||
let lock = await acquireGatewayLock({ port: params.lockPort });
|
||||
|
||||
Reference in New Issue
Block a user