mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-12 22:40:24 +00:00
PR #3015 added --yes and -y flags to the delete command but didn't add them to KNOWN_FLAGS in flags.ts. This caused `spawn delete --name foo --yes` to fail with "Unknown flag: --yes" because checkUnknownFlags runs before dispatchDeleteCommand strips these flags. Also adds delete-specific flags to --help documentation. Agent: code-health Co-authored-by: B <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
70 lines
1.4 KiB
TypeScript
70 lines
1.4 KiB
TypeScript
/** CLI flag definitions and utilities — single source of truth for flag validation */
|
|
|
|
export const KNOWN_FLAGS = new Set([
|
|
"--help",
|
|
"-h",
|
|
"--version",
|
|
"-v",
|
|
"-V",
|
|
"--prompt",
|
|
"-p",
|
|
"--prompt-file",
|
|
"-f",
|
|
"--dry-run",
|
|
"-n",
|
|
"--debug",
|
|
"--headless",
|
|
"--output",
|
|
"--name",
|
|
"--default",
|
|
"-a",
|
|
"-c",
|
|
"--agent",
|
|
"--cloud",
|
|
"--clear",
|
|
"--custom",
|
|
"--reauth",
|
|
"--zone",
|
|
"--region",
|
|
"--machine-type",
|
|
"--size",
|
|
"--prune",
|
|
"--json",
|
|
"--beta",
|
|
"--model",
|
|
"-m",
|
|
"--config",
|
|
"--steps",
|
|
"--fast",
|
|
"--user",
|
|
"-u",
|
|
"--yes",
|
|
"-y",
|
|
]);
|
|
|
|
/** Return the first unknown flag in args, or null if all are known/positional */
|
|
export function findUnknownFlag(args: string[]): string | null {
|
|
for (const arg of args) {
|
|
if (
|
|
(arg.startsWith("--") || (arg.startsWith("-") && arg.length > 1 && !/^-\d/.test(arg))) &&
|
|
!KNOWN_FLAGS.has(arg)
|
|
) {
|
|
return arg;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/** Expand --flag=value into --flag value so all flag parsing works uniformly */
|
|
export function expandEqualsFlags(args: string[]): string[] {
|
|
const result: string[] = [];
|
|
for (const arg of args) {
|
|
if (arg.startsWith("--") && arg.includes("=")) {
|
|
const eqIdx = arg.indexOf("=");
|
|
result.push(arg.slice(0, eqIdx), arg.slice(eqIdx + 1));
|
|
} else {
|
|
result.push(arg);
|
|
}
|
|
}
|
|
return result;
|
|
}
|