(args: string[])
| 63 | * `--raw` value) so the user gets a clear error instead of a silent misparse. |
| 64 | */ |
| 65 | export function parseOutArgs(args: string[]): OutArgs { |
| 66 | let outPath: string | undefined; |
| 67 | let raw = false; |
| 68 | const rest: string[] = []; |
| 69 | for (let i = 0; i < args.length; i++) { |
| 70 | const a = args[i]; |
| 71 | if (a === '--out') { |
| 72 | if (outPath !== undefined) throw new Error('--out specified more than once'); |
| 73 | const val = args[i + 1]; |
| 74 | if (val === undefined || val.startsWith('--')) throw new Error('--out requires a file path'); |
| 75 | outPath = val; |
| 76 | i++; |
| 77 | } else if (a.startsWith('--out=')) { |
| 78 | if (outPath !== undefined) throw new Error('--out specified more than once'); |
| 79 | const val = a.slice('--out='.length); |
| 80 | if (val === '') throw new Error('--out requires a file path'); |
| 81 | outPath = val; |
| 82 | } else if (a === '--raw') { |
| 83 | raw = true; |
| 84 | } else if (a.startsWith('--raw=')) { |
| 85 | const v = a.slice('--raw='.length).toLowerCase(); |
| 86 | if (v !== 'true' && v !== 'false') throw new Error('--raw must be true or false'); |
| 87 | raw = v === 'true'; |
| 88 | } else { |
| 89 | rest.push(a); |
| 90 | } |
| 91 | } |
| 92 | return { outPath, raw, rest }; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * True iff an arg list contains an `--out` flag in any accepted form |
no test coverage detected