mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 04:47:03 -06:00
e9b959aaaa
Co-authored-by: Peter Steinberger <steipete@macos.shared>
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import { consumeRootOptionToken } from "../infra/cli-root-options.js";
|
|
import { findMachineOutputRootCommandIndex } from "./machine-output-argv.js";
|
|
|
|
function hasFlag(argv: readonly string[], flag: string): boolean {
|
|
for (const arg of argv.slice(2)) {
|
|
if (arg === "--") {
|
|
return false;
|
|
}
|
|
if (arg === flag) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function resolveConfigSubcommand(argv: readonly string[]): string | null {
|
|
const rootIndex = findMachineOutputRootCommandIndex(argv);
|
|
if (rootIndex === null) {
|
|
return null;
|
|
}
|
|
const args = argv.slice(2);
|
|
for (let index = rootIndex - 1; index < args.length; index += 1) {
|
|
const arg = args[index];
|
|
if (!arg || arg === "--") {
|
|
return null;
|
|
}
|
|
const rootConsumed = consumeRootOptionToken(args, index);
|
|
if (rootConsumed > 0) {
|
|
index += rootConsumed - 1;
|
|
continue;
|
|
}
|
|
if (arg === "--section") {
|
|
index += 1;
|
|
continue;
|
|
}
|
|
if (arg.startsWith("--section=")) {
|
|
continue;
|
|
}
|
|
if (!arg.startsWith("-")) {
|
|
return arg;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/** Config values, paths, and schemas reserve stdout for machine-consumed output. */
|
|
export function isConfigMachineOutput(argv: readonly string[]): boolean {
|
|
const subcommand = resolveConfigSubcommand(argv);
|
|
return subcommand === "get" || subcommand === "file" || subcommand === "schema";
|
|
}
|
|
|
|
/** Config set uses --json as a parser alias except when dry-run emits a JSON report. */
|
|
export function isConfigSetJsonParseOnly(argv: readonly string[]): boolean {
|
|
return hasFlag(argv, "--json") && !hasFlag(argv, "--dry-run");
|
|
}
|