CLI: keep passthrough --profile args after --

This commit is contained in:
Tristan Manchester 2026-02-22 08:39:34 +01:00
parent 902396c8b6
commit e13cc5b66b
2 changed files with 78 additions and 0 deletions

View File

@ -68,6 +68,72 @@ describe("parseCliProfileArgs", () => {
expect(res.ok).toBe(false);
});
it("does not intercept --profile after passthrough terminator", () => {
const res = parseCliProfileArgs([
"node",
"openclaw",
"nodes",
"run",
"--node",
"abc123",
"--",
"aws",
"--profile",
"prod",
"sts",
"get-caller-identity",
]);
if (!res.ok) {
throw new Error(res.error);
}
expect(res.profile).toBeNull();
expect(res.argv).toEqual([
"node",
"openclaw",
"nodes",
"run",
"--node",
"abc123",
"--",
"aws",
"--profile",
"prod",
"sts",
"get-caller-identity",
]);
});
it("keeps passthrough --profile when global --profile is set before terminator", () => {
const res = parseCliProfileArgs([
"node",
"openclaw",
"--profile",
"work",
"nodes",
"run",
"--",
"aws",
"--profile=prod",
"sts",
"get-caller-identity",
]);
if (!res.ok) {
throw new Error(res.error);
}
expect(res.profile).toBe("work");
expect(res.argv).toEqual([
"node",
"openclaw",
"nodes",
"run",
"--",
"aws",
"--profile=prod",
"sts",
"get-caller-identity",
]);
});
it("parses --profile value and strips it", () => {
const res = parseCliProfileArgs(["node", "openclaw", "--profile", "work", "status"]);
if (!res.ok) {

View File

@ -36,6 +36,7 @@ export function parseCliProfileArgs(argv: string[]): CliProfileParseResult {
let profile: string | null = null;
let sawDev = false;
let sawCommand = false;
let sawTerminator = false;
const args = argv.slice(2);
for (let i = 0; i < args.length; i += 1) {
@ -44,6 +45,17 @@ export function parseCliProfileArgs(argv: string[]): CliProfileParseResult {
continue;
}
if (sawTerminator) {
out.push(arg);
continue;
}
if (arg === "--") {
sawTerminator = true;
out.push(arg);
continue;
}
if (sawCommand && arg !== "--profile" && !arg.startsWith("--profile=")) {
out.push(arg);
continue;