* Parse stdbuf's flags (-i/-o/-e in fused/space-separated/long-= forms). * Returns argv index of wrapped COMMAND, or -1 if unparseable or no flags * consumed (stdbuf without flags is inert). Mirrors checkSemantics (ast.ts).
(a: readonly string[])
| 1223 | * consumed (stdbuf without flags is inert). Mirrors checkSemantics (ast.ts). |
| 1224 | */ |
| 1225 | function skipStdbufFlags(a: readonly string[]): number { |
| 1226 | let i = 1 |
| 1227 | while (i < a.length) { |
| 1228 | const arg = a[i]! |
| 1229 | if (/^-[ioe]$/.test(arg) && a[i + 1]) i += 2 |
| 1230 | else if (/^-[ioe]./.test(arg)) i++ |
| 1231 | else if (/^--(input|output|error)=/.test(arg)) i++ |
| 1232 | else if (arg.startsWith('-')) |
| 1233 | return -1 // unknown flag: fail closed |
| 1234 | else break |
| 1235 | } |
| 1236 | return i > 1 && i < a.length ? i : -1 |
| 1237 | } |
| 1238 | |
| 1239 | /** |
| 1240 | * Parse env's VAR=val and safe flags (-i/-0/-v/-u NAME). Returns argv index |
no outgoing calls
no test coverage detected