export function tokenizeArgs(input: string): string[] { const tokens: string[] = []; let current = ""; let quote: '"' | "'" | undefined; let escaped = false; for (const char of input) { if (escaped) { current += char; escaped = false; continue; } if (char === "\\") { escaped = true; continue; } if (quote) { if (char === quote) quote = undefined; else current += char; continue; } if (char === '"' || char === "'") { quote = char; continue; } if (/\s/.test(char)) { if (current) { tokens.push(current); current = ""; } continue; } current += char; } if (escaped) current += "\\"; if (quote) throw new Error(`Unclosed ${quote} quote`); if (current) tokens.push(current); return tokens; } export function takeValue(tokens: string[], index: number, flag: string): string { const value = tokens[index + 1]; if (!value || value.startsWith("--")) throw new Error(`${flag} requires a value`); return value; } export function takeOptionalValue(tokens: string[], index: number): string | undefined { const value = tokens[index + 1]; return value && !value.startsWith("--") ? value : undefined; }