mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-26 01:11:37 +00:00
refactor(cli): separate json payload output from logging
This commit is contained in:
@@ -66,7 +66,7 @@ export function registerNodesCameraCommands(nodes: Command) {
|
||||
const devices = Array.isArray(payload.devices) ? payload.devices : [];
|
||||
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(JSON.stringify(devices, null, 2));
|
||||
defaultRuntime.writeJson(devices);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ export function registerNodesCameraCommands(nodes: Command) {
|
||||
}
|
||||
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(JSON.stringify({ files: results }, null, 2));
|
||||
defaultRuntime.writeJson({ files: results });
|
||||
return;
|
||||
}
|
||||
defaultRuntime.log(results.map((r) => `MEDIA:${shortenHomePath(r.path)}`).join("\n"));
|
||||
@@ -241,20 +241,14 @@ export function registerNodesCameraCommands(nodes: Command) {
|
||||
});
|
||||
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
file: {
|
||||
facing,
|
||||
path: filePath,
|
||||
durationMs: payload.durationMs,
|
||||
hasAudio: payload.hasAudio,
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
defaultRuntime.writeJson({
|
||||
file: {
|
||||
facing,
|
||||
path: filePath,
|
||||
durationMs: payload.durationMs,
|
||||
hasAudio: payload.hasAudio,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
defaultRuntime.log(`MEDIA:${shortenHomePath(filePath)}`);
|
||||
|
||||
@@ -65,9 +65,7 @@ export function registerNodesCanvasCommands(nodes: Command) {
|
||||
await writeBase64ToFile(filePath, payload.base64);
|
||||
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(
|
||||
JSON.stringify({ file: { path: filePath, format: payload.format } }, null, 2),
|
||||
);
|
||||
defaultRuntime.writeJson({ file: { path: filePath, format: payload.format } });
|
||||
return;
|
||||
}
|
||||
defaultRuntime.log(`MEDIA:${shortenHomePath(filePath)}`);
|
||||
@@ -169,7 +167,7 @@ export function registerNodesCanvasCommands(nodes: Command) {
|
||||
javaScript: js,
|
||||
});
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(JSON.stringify(raw, null, 2));
|
||||
defaultRuntime.writeJson(raw);
|
||||
return;
|
||||
}
|
||||
const payload =
|
||||
|
||||
@@ -333,7 +333,7 @@ export function registerNodesInvokeCommands(nodes: Command) {
|
||||
}
|
||||
|
||||
const result = await callGatewayCli("node.invoke", opts, invokeParams);
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
defaultRuntime.writeJson(result);
|
||||
});
|
||||
}),
|
||||
{ timeoutMs: 30_000 },
|
||||
@@ -421,7 +421,7 @@ export function registerNodesInvokeCommands(nodes: Command) {
|
||||
|
||||
const result = await callGatewayCli("node.invoke", opts, invokeParams);
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
defaultRuntime.writeJson(result);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ export function registerNodesLocationCommands(nodes: Command) {
|
||||
: {};
|
||||
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(JSON.stringify(payload, null, 2));
|
||||
defaultRuntime.writeJson(payload);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ export function registerNodesLocationCommands(nodes: Command) {
|
||||
defaultRuntime.log(`${lat},${lon}${accText}`);
|
||||
return;
|
||||
}
|
||||
defaultRuntime.log(JSON.stringify(payload));
|
||||
defaultRuntime.writeJson(payload, 0);
|
||||
});
|
||||
}),
|
||||
{ timeoutMs: 30_000 },
|
||||
|
||||
@@ -46,7 +46,7 @@ export function registerNodesNotifyCommand(nodes: Command) {
|
||||
|
||||
const result = await callGatewayCli("node.invoke", opts, invokeParams);
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
defaultRuntime.writeJson(result);
|
||||
return;
|
||||
}
|
||||
const { ok } = getNodesTheme();
|
||||
|
||||
@@ -17,7 +17,7 @@ export function registerNodesPairingCommands(nodes: Command) {
|
||||
const result = await callGatewayCli("node.pair.list", opts, {});
|
||||
const { pending } = parsePairingList(result);
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(JSON.stringify(pending, null, 2));
|
||||
defaultRuntime.writeJson(pending);
|
||||
return;
|
||||
}
|
||||
if (pending.length === 0) {
|
||||
@@ -50,7 +50,7 @@ export function registerNodesPairingCommands(nodes: Command) {
|
||||
const result = await callGatewayCli("node.pair.approve", opts, {
|
||||
requestId,
|
||||
});
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
defaultRuntime.writeJson(result);
|
||||
});
|
||||
}),
|
||||
);
|
||||
@@ -65,7 +65,7 @@ export function registerNodesPairingCommands(nodes: Command) {
|
||||
const result = await callGatewayCli("node.pair.reject", opts, {
|
||||
requestId,
|
||||
});
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
defaultRuntime.writeJson(result);
|
||||
});
|
||||
}),
|
||||
);
|
||||
@@ -90,7 +90,7 @@ export function registerNodesPairingCommands(nodes: Command) {
|
||||
displayName: name,
|
||||
});
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
defaultRuntime.writeJson(result);
|
||||
return;
|
||||
}
|
||||
const { ok } = getNodesTheme();
|
||||
|
||||
@@ -52,7 +52,7 @@ export function registerNodesPushCommand(nodes: Command) {
|
||||
|
||||
const result = await callGatewayCli("push.test", opts, params);
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
defaultRuntime.writeJson(result);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,21 +57,15 @@ export function registerNodesScreenCommands(nodes: Command) {
|
||||
const written = await writeScreenRecordToFile(filePath, parsed.base64);
|
||||
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
file: {
|
||||
path: written.path,
|
||||
durationMs: parsed.durationMs,
|
||||
fps: parsed.fps,
|
||||
screenIndex: parsed.screenIndex,
|
||||
hasAudio: parsed.hasAudio,
|
||||
},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
defaultRuntime.writeJson({
|
||||
file: {
|
||||
path: written.path,
|
||||
durationMs: parsed.durationMs,
|
||||
fps: parsed.fps,
|
||||
screenIndex: parsed.screenIndex,
|
||||
hasAudio: parsed.hasAudio,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
defaultRuntime.log(`MEDIA:${shortenHomePath(written.path)}`);
|
||||
|
||||
@@ -147,7 +147,7 @@ export function registerNodesStatusCommands(nodes: Command) {
|
||||
|
||||
if (opts.json) {
|
||||
const ts = typeof obj.ts === "number" ? obj.ts : Date.now();
|
||||
defaultRuntime.log(JSON.stringify({ ...obj, ts, nodes: filtered }, null, 2));
|
||||
defaultRuntime.writeJson({ ...obj, ts, nodes: filtered });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ export function registerNodesStatusCommands(nodes: Command) {
|
||||
nodeId,
|
||||
});
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(JSON.stringify(result, null, 2));
|
||||
defaultRuntime.writeJson(result);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -350,9 +350,7 @@ export function registerNodesStatusCommands(nodes: Command) {
|
||||
);
|
||||
|
||||
if (opts.json) {
|
||||
defaultRuntime.log(
|
||||
JSON.stringify({ pending: pendingRows, paired: filteredPaired }, null, 2),
|
||||
);
|
||||
defaultRuntime.writeJson({ pending: pendingRows, paired: filteredPaired });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user