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

Function shell_complete

src/click/shell_completion.py:19–55  ·  view source on GitHub ↗

Perform shell completion for the given CLI program. :param cli: Command being called. :param ctx_args: Extra arguments to pass to ``cli.make_context``. :param prog_name: Name of the executable in the shell. :param complete_var: Name of the environment variable that holds

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

Source from the content-addressed store, hash-verified

17
18
19def shell_complete(
20 cli: Command,
21 ctx_args: cabc.MutableMapping[str, t.Any],
22 prog_name: str,
23 complete_var: str,
24 instruction: str,
25) -> t.Literal[0, 1]:
26 """Perform shell completion for the given CLI program.
27
28 :param cli: Command being called.
29 :param ctx_args: Extra arguments to pass to
30 ``cli.make_context``.
31 :param prog_name: Name of the executable in the shell.
32 :param complete_var: Name of the environment variable that holds
33 the completion instruction.
34 :param instruction: Value of ``complete_var`` with the completion
35 instruction and shell, in the form ``instruction_shell``.
36 :return: Status code to exit with.
37 """
38 shell, _, instruction = instruction.partition("_")
39 comp_cls = get_completion_class(shell)
40
41 if comp_cls is None:
42 return 1
43
44 comp = comp_cls(cli, ctx_args, prog_name, complete_var)
45
46 # Write bytes, otherwise Windows text stdout translates LF to CRLF and breaks.
47 if instruction == "source":
48 echo(comp.source().encode(), nl=False)
49 return 0
50
51 if instruction == "complete":
52 echo(comp.complete().encode())
53 return 0
54
55 return 1
56
57
58if t.TYPE_CHECKING:

Callers 2

Calls 4

get_completion_classFunction · 0.85
completeMethod · 0.80
echoFunction · 0.70
sourceMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…