( tokens: ReadonlyArray<Token>, registry: FlagRegistry )
| 522 | * @internal |
| 523 | */ |
| 524 | export const consumeKnownFlags = ( |
| 525 | tokens: ReadonlyArray<Token>, |
| 526 | registry: FlagRegistry |
| 527 | ): { flagMap: FlagMap; remainder: ReadonlyArray<Token>; errors: ReadonlyArray<CliError.InvalidValue> } => { |
| 528 | const flagMap = createEmptyFlagMap(registry.params) |
| 529 | const remainder: Array<Token> = [] |
| 530 | const errors: Array<CliError.InvalidValue> = [] |
| 531 | const cursor = makeCursor(tokens) |
| 532 | |
| 533 | for (let t = cursor.take(); t; t = cursor.take()) { |
| 534 | if (!isFlagToken(t)) { |
| 535 | remainder.push(t) |
| 536 | continue |
| 537 | } |
| 538 | |
| 539 | const resolved = resolveFlag(t, registry) |
| 540 | if (!resolved) { |
| 541 | remainder.push(t) |
| 542 | continue |
| 543 | } |
| 544 | |
| 545 | const consumed = consumeFlagValue(cursor, t, resolved.param, resolved.negated) |
| 546 | if (consumed._tag === "Error") { |
| 547 | errors.push(consumed.error) |
| 548 | continue |
| 549 | } |
| 550 | if (consumed.value !== undefined) { |
| 551 | flagMap[resolved.param.name].push(consumed.value) |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | return { flagMap, remainder, errors } |
| 556 | } |
| 557 | |
| 558 | const extractFlagParams = (command: Command.Any): ReadonlyArray<FlagParam> => { |
| 559 | const commandImpl = toImpl(command) |
no test coverage detected