openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
37 lines (36 loc) • 1.3 kB
JavaScript
import { O as hasCommanderOptionToken, s as hasFlag } from "./argv-CbnKpH-r.mjs";
//#region src/cli/program/json-mode.ts
const jsonModeSymbol = Symbol("openclaw.cli.jsonMode");
const JSON_FLAG = /* @__PURE__ */ new Set(["--json"]);
function commandDefinesJsonOption(e) {
return e.options.some((e) => e.long === "--json");
}
function getCommandJsonMode(e, t = process.argv) {
const n = hasFlag(t, "--json") && !hasCommanderOptionToken(e, t, JSON_FLAG, "value");
const r = e.optsWithGlobals().json === true || n;
for (let n = e; n; n = n.parent ?? null) {
const i = n[jsonModeSymbol];
if (i?.resolve?.({
command: e,
argv: t,
stdoutIsTTY: process.stdout.isTTY || false
})) return i.mode;
if (i && !i.resolve && r) return i.mode;
if (r && commandDefinesJsonOption(n)) return "output";
}
return null;
}
/** Mark a command as having a special JSON mode beyond ordinary `--json` output. */
function setCommandJsonMode(e, t, n) {
e[jsonModeSymbol] = {
mode: t,
...n ? { resolve: n } : {}
};
return e;
}
/** Return true when the command's active mode owns machine-readable JSON stdout. */
function isCommandJsonOutputMode(e, t = process.argv) {
return getCommandJsonMode(e, t) === "output";
}
//#endregion
export { setCommandJsonMode as n, isCommandJsonOutputMode as t };