UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

37 lines (36 loc) 1.42 kB
import { c as hasFlag } from "./argv-CnfL__6a.js"; //#region src/cli/program/json-mode.ts const jsonModeSymbol = Symbol("openclaw.cli.jsonMode"); function commandDefinesJsonOption(command) { return command.options.some((option) => option.long === "--json"); } function getDeclaredCommandJsonMode(command) { for (let current = command; current; current = current.parent ?? null) { const metadata = current[jsonModeSymbol]; if (metadata) return metadata; if (commandDefinesJsonOption(current)) return "output"; } return null; } function commandSelectedJsonFlag(command, argv) { const commandWithGlobals = command; if (typeof commandWithGlobals.optsWithGlobals === "function") { if (commandWithGlobals.optsWithGlobals().json === true) return true; } return hasFlag(argv, "--json"); } /** Mark a command as having a special JSON mode beyond ordinary JSON output. */ function setCommandJsonMode(command, mode) { command[jsonModeSymbol] = mode; return command; } function getCommandJsonMode(command, argv = process.argv) { if (!commandSelectedJsonFlag(command, argv)) return null; return getDeclaredCommandJsonMode(command); } /** Return true only when `--json` selects machine-readable command output. */ function isCommandJsonOutputMode(command, argv = process.argv) { return getCommandJsonMode(command, argv) === "output"; } //#endregion export { setCommandJsonMode as n, isCommandJsonOutputMode as t };