(argv: string[], globalOptions: OptionDef[] = [])
| 44 | * correctly produces ['text', 'chat'] instead of ['json', 'text', 'chat']. |
| 45 | */ |
| 46 | export function scanCommandPath(argv: string[], globalOptions: OptionDef[] = []): string[] { |
| 47 | const globalSchema = buildSchema(globalOptions); |
| 48 | const path: string[] = []; |
| 49 | let i = 0; |
| 50 | while (i < argv.length) { |
| 51 | const arg = argv[i]!; |
| 52 | if (arg === '--') break; |
| 53 | |
| 54 | if (arg.startsWith('--')) { |
| 55 | const eqIdx = arg.indexOf('='); |
| 56 | const key = eqIdx !== -1 ? arg.slice(2, eqIdx) : arg.slice(2); |
| 57 | const camelKey = kebabToCamel(key); |
| 58 | |
| 59 | if (!globalSchema.booleans.has(camelKey) && eqIdx === -1) { |
| 60 | i += 2; |
| 61 | } else { |
| 62 | i += 1; |
| 63 | } |
| 64 | continue; |
| 65 | } |
| 66 | |
| 67 | if (arg.startsWith('-')) { i++; continue; } |
| 68 | |
| 69 | path.push(arg); |
| 70 | i++; |
| 71 | } |
| 72 | return path; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Full flag parse. Types are derived entirely from the provided OptionDef schema: |
no test coverage detected