(args: string[])
| 8 | * Supports: --key value, --key=value, --flag (boolean true) |
| 9 | */ |
| 10 | export function parseArgs(args: string[]): Record<string, string> { |
| 11 | const result: Record<string, string> = {}; |
| 12 | for (let i = 0; i < args.length; i++) { |
| 13 | const arg = args[i]; |
| 14 | if (!arg.startsWith("--")) continue; |
| 15 | |
| 16 | const eqIndex = arg.indexOf("="); |
| 17 | if (eqIndex !== -1) { |
| 18 | const key = arg.slice(2, eqIndex); |
| 19 | result[key] = arg.slice(eqIndex + 1); |
| 20 | } else { |
| 21 | const key = arg.slice(2); |
| 22 | const next = args[i + 1]; |
| 23 | if (next && !next.startsWith("--")) { |
| 24 | result[key] = next; |
| 25 | i++; |
| 26 | } else { |
| 27 | result[key] = "true"; |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | return result; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Convert kebab-case keys to camelCase. |
no outgoing calls
no test coverage detected