fix(cli): prevent boolean flags from swallowing positional args and unify aipro arg parsing
This commit is contained in:
1 parent
d0af46b445
commit
c60d49fb8c
4 files changed
+117
-25
No files matched your search
+1
-21
@@ -31,27 +31,7 @@ export async function runAiProCli(rawArgs: string[]): Promise<{ stdout: string;
|
||||
const service = new ApprovalService(repo);
|
||||
let client: Awaited<ReturnType<typeof createSessionClient>> | undefined;
|
||||
|
||||
const positional: string[] = [];
|
||||
for (let i = 0; i < rawArgs.length; i++) {
|
||||
const arg = rawArgs[i];
|
||||
if (arg === "--") {
|
||||
positional.push(...rawArgs.slice(i + 1));
|
||||
break;
|
||||
}
|
||||
if (arg.startsWith("-")) {
|
||||
const eqIdx = arg.indexOf("=");
|
||||
if (eqIdx === -1) {
|
||||
const flagName = arg.replace(/^--?/, "").toLowerCase();
|
||||
const isBool = ["raw", "json", "j", "help", "h", "version", "v", "yes", "y", "confirm", "apply", "execute"].includes(flagName);
|
||||
if (!isBool && i + 1 < rawArgs.length && !rawArgs[i + 1].startsWith("-")) {
|
||||
i++; // skip option value
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
positional.push(arg);
|
||||
}
|
||||
|
||||
const positional = parsed.positional ?? [parsed.area, parsed.action, ...parsed.args].filter((v): v is string => Boolean(v));
|
||||
const command = (positional[0] || "help").toLowerCase();
|
||||
const jsonMode = booleanOption(parsed.options, ["json", "j"]);
|
||||
const targetSn = positional[1] || stringOption(parsed.options, ["code", "sn", "id", "target"]);
|
||||
|
||||
Reference in new issue
Block a user