openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
22 lines (21 loc) • 1.09 kB
JavaScript
import { n as normalizeProfileName } from "./profile-utils-d6OWXWRX.mjs";
//#region src/cli/command-format.ts
const CLI_PREFIX_RE = /^(?:pnpm|npm|bunx|npx)\s+openclaw\b|^openclaw\b/;
const CONTAINER_FLAG_RE = /(?:^|\s)--container(?:\s|=|$)/;
const PROFILE_FLAG_RE = /(?:^|\s)--profile(?:\s|=|$)/;
const DEV_FLAG_RE = /(?:^|\s)--dev(?:\s|$)/;
const UPDATE_RE = /^(?:\s+--(?:dev|no-color|(?:profile|log-level)[=\s]+\S+))*\s+update(?:\s|$)/;
const CONTAINER_HINT_RE = /^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$/;
function formatCliCommand(e, t = process.env) {
const n = t.OPENCLAW_CONTAINER_HINT?.trim();
const r = n && CONTAINER_HINT_RE.test(n) ? n : void 0;
const i = normalizeProfileName(t.OPENCLAW_PROFILE);
if (!r && !i) return e;
if (!CLI_PREFIX_RE.test(e)) return e;
let a;
if (r && !CONTAINER_FLAG_RE.test(e) && !UPDATE_RE.test(e.replace(CLI_PREFIX_RE, ""))) a = `--container ${r}`;
if (!r && i && !PROFILE_FLAG_RE.test(e) && !DEV_FLAG_RE.test(e)) a = `--profile ${i}`;
return a ? e.replace(CLI_PREFIX_RE, (e) => `${e} ${a}`) : e;
}
//#endregion
export { formatCliCommand as t };