Find the Click object that will handle the completion of the incomplete value. Return the object and the incomplete value. :param ctx: Invocation context for the command represented by the parsed complete args. :param args: List of complete args before the incomplete value.
(
ctx: Context, args: list[str], incomplete: str
)
| 659 | |
| 660 | |
| 661 | def _resolve_incomplete( |
| 662 | ctx: Context, args: list[str], incomplete: str |
| 663 | ) -> tuple[Command | Parameter, str]: |
| 664 | """Find the Click object that will handle the completion of the |
| 665 | incomplete value. Return the object and the incomplete value. |
| 666 | |
| 667 | :param ctx: Invocation context for the command represented by |
| 668 | the parsed complete args. |
| 669 | :param args: List of complete args before the incomplete value. |
| 670 | :param incomplete: Value being completed. May be empty. |
| 671 | """ |
| 672 | # Different shells treat an "=" between a long option name and |
| 673 | # value differently. Might keep the value joined, return the "=" |
| 674 | # as a separate item, or return the split name and value. Always |
| 675 | # split and discard the "=" to make completion easier. |
| 676 | if incomplete == "=": |
| 677 | incomplete = "" |
| 678 | elif "=" in incomplete and _start_of_option(ctx, incomplete): |
| 679 | name, _, incomplete = incomplete.partition("=") |
| 680 | args.append(name) |
| 681 | |
| 682 | # The "--" marker tells Click to stop treating values as options |
| 683 | # even if they start with the option character. If it hasn't been |
| 684 | # given and the incomplete arg looks like an option, the current |
| 685 | # command will provide option name completions. |
| 686 | if "--" not in args and _start_of_option(ctx, incomplete): |
| 687 | return ctx.command, incomplete |
| 688 | |
| 689 | params = ctx.command.get_params(ctx) |
| 690 | |
| 691 | # If the last complete arg is an option name with an incomplete |
| 692 | # value, the option will provide value completions. |
| 693 | for param in params: |
| 694 | if _is_incomplete_option(ctx, args, param): |
| 695 | return param, incomplete |
| 696 | |
| 697 | # It's not an option name or value. The first argument without a |
| 698 | # parsed value will provide value completions. |
| 699 | for param in params: |
| 700 | if _is_incomplete_argument(ctx, param): |
| 701 | return param, incomplete |
| 702 | |
| 703 | # There were no unparsed arguments, the command may be a group that |
| 704 | # will provide command name completions. |
| 705 | return ctx.command, incomplete |
no test coverage detected