(
tokens: ReadonlyArray<Token>,
command: Command.Any,
ignoredRegistries: ReadonlyArray<FlagRegistry>
)
| 668 | const errors: Array<CliError.InvalidValue> = [] |
| 669 | |
| 670 | const consumeLevel = ( |
| 671 | tokens: ReadonlyArray<Token>, |
| 672 | command: Command.Any, |
| 673 | ignoredRegistries: ReadonlyArray<FlagRegistry> |
| 674 | ): ReadonlyArray<Token> => { |
| 675 | const localRegistry = createFlagRegistry(extractFlagParams(command)) |
| 676 | const inheritedRegistry = createFlagRegistry(extractContextFlagParams(command)) |
| 677 | const subIndex = buildSubcommandIndex(command.subcommands) |
| 678 | const cursor = makeCursor(tokens) |
| 679 | const remainder: Array<Token> = [] |
| 680 | let awaitingFirstValue = true |
| 681 | |
| 682 | for (let token = cursor.take(); token; token = cursor.take()) { |
| 683 | if (isFlagToken(token)) { |
| 684 | const ignored = resolveFromRegistries(token, ignoredRegistries) |
| 685 | if (ignored !== undefined) { |
| 686 | preserveFlag(remainder, cursor, token, ignored) |
| 687 | continue |
| 688 | } |
| 689 | |
| 690 | const inherited = resolveFlag(token, inheritedRegistry) |
| 691 | if (inherited !== undefined) { |
| 692 | preserveFlag(remainder, cursor, token, inherited) |
| 693 | continue |
| 694 | } |
| 695 | |
| 696 | const local = resolveFlag(token, localRegistry) |
| 697 | const global = resolveFlag(token, registry) |
| 698 | if (local !== undefined) { |
| 699 | if ( |
| 700 | global === undefined || !awaitingFirstValue || |
| 701 | !localFlagWouldPrecedeSubcommand(token, cursor.rest(), local, subIndex, [ |
| 702 | localRegistry, |
| 703 | inheritedRegistry, |
| 704 | registry |
| 705 | ]) |
| 706 | ) { |
| 707 | preserveFlag(remainder, cursor, token, local) |
| 708 | continue |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | if (global !== undefined) { |
| 713 | const consumed = consumeFlagValueWithTokens(cursor, token, global.param, global.negated) |
| 714 | if (consumed._tag === "Error") { |
| 715 | errors.push(consumed.error) |
| 716 | continue |
| 717 | } |
| 718 | if (consumed.value !== undefined) { |
| 719 | flagMap[global.param.name].push(consumed.value) |
| 720 | } |
| 721 | continue |
| 722 | } |
| 723 | |
| 724 | remainder.push(token) |
| 725 | continue |
| 726 | } |
| 727 |
no test coverage detected