MCPcopy
hub / github.com/pallets/click / _resolve_context

Function _resolve_context

src/click/shell_completion.py:600–658  ·  view source on GitHub ↗

Produce the context hierarchy starting with the command and traversing the complete arguments. This only follows the commands, it doesn't trigger input prompts or callbacks. :param cli: Command being called. :param prog_name: Name of the executable in the shell. :param args: Lis

(
    cli: Command,
    ctx_args: cabc.MutableMapping[str, t.Any],
    prog_name: str,
    args: list[str],
)

Source from the content-addressed store, hash-verified

598
599
600def _resolve_context(
601 cli: Command,
602 ctx_args: cabc.MutableMapping[str, t.Any],
603 prog_name: str,
604 args: list[str],
605) -> Context:
606 """Produce the context hierarchy starting with the command and
607 traversing the complete arguments. This only follows the commands,
608 it doesn't trigger input prompts or callbacks.
609
610 :param cli: Command being called.
611 :param prog_name: Name of the executable in the shell.
612 :param args: List of complete args before the incomplete value.
613 """
614 ctx_args["resilient_parsing"] = True
615 with cli.make_context(prog_name, args.copy(), **ctx_args) as ctx:
616 args = ctx._protected_args + ctx.args
617
618 while args:
619 command = ctx.command
620
621 if isinstance(command, Group):
622 if not command.chain:
623 name, cmd, args = command.resolve_command(ctx, args)
624
625 if cmd is None:
626 return ctx
627
628 with cmd.make_context(
629 name, args, parent=ctx, resilient_parsing=True
630 ) as sub_ctx:
631 ctx = sub_ctx
632 args = ctx._protected_args + ctx.args
633 else:
634 sub_ctx = ctx
635
636 while args:
637 name, cmd, args = command.resolve_command(ctx, args)
638
639 if cmd is None:
640 return ctx
641
642 with cmd.make_context(
643 name,
644 args,
645 parent=ctx,
646 allow_extra_args=True,
647 allow_interspersed_args=False,
648 resilient_parsing=True,
649 ) as sub_sub_ctx:
650 sub_ctx = sub_sub_ctx
651 args = sub_ctx.args
652
653 ctx = sub_ctx
654 args = [*sub_ctx._protected_args, *sub_ctx.args]
655 else:
656 break
657

Callers 1

get_completionsMethod · 0.85

Calls 2

make_contextMethod · 0.80
resolve_commandMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…