]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_internal/commands/completion.py
3 from optparse
import Values
4 from typing
import List
6 from pip
._internal
.cli
.base_command
import Command
7 from pip
._internal
.cli
.status_codes
import SUCCESS
8 from pip
._internal
.utils
.misc
import get_prog
11 # pip {shell} completion start{script}# pip {shell} completion end
14 COMPLETION_SCRIPTS
= {
18 COMPREPLY=( $( COMP_WORDS="${{COMP_WORDS[*]}}" \\
19 COMP_CWORD=$COMP_CWORD \\
20 PIP_AUTO_COMPLETE=1 $1 2>/dev/null ) )
22 complete -o default -F _pip_completion {prog}
25 #compdef -P pip[0-9.]#
26 compadd $( COMP_WORDS="$words[*]" \\
27 COMP_CWORD=$((CURRENT-1)) \\
28 PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null )
31 function __fish_complete_pip
32 set -lx COMP_WORDS (commandline -o) ""
33 set -lx COMP_CWORD ( \\
34 math (contains -i -- (commandline -t) $COMP_WORDS)-1 \\
36 set -lx PIP_AUTO_COMPLETE 1
37 string split \\ -- (eval $COMP_WORDS[1])
39 complete -fa "(__fish_complete_pip)" -c {prog}
42 if ((Test-Path Function:\\TabExpansion) -and -not `
43 (Test-Path Function:\\_pip_completeBackup)) {{
44 Rename-Item Function:\\TabExpansion _pip_completeBackup
46 function TabExpansion($line, $lastWord) {{
47 $lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart()
48 if ($lastBlock.StartsWith("{prog} ")) {{
49 $Env:COMP_WORDS=$lastBlock
50 $Env:COMP_CWORD=$lastBlock.Split().Length - 1
51 $Env:PIP_AUTO_COMPLETE=1
53 Remove-Item Env:COMP_WORDS
54 Remove-Item Env:COMP_CWORD
55 Remove-Item Env:PIP_AUTO_COMPLETE
57 elseif (Test-Path Function:\\_pip_completeBackup) {{
58 # Fall back on existing tab expansion
59 _pip_completeBackup $line $lastWord
66 class CompletionCommand(Command
):
67 """A helper command to be used for command completion."""
69 ignore_require_venv
= True
71 def add_options(self
) -> None:
72 self
.cmd_opts
.add_option(
78 help="Emit completion code for bash",
80 self
.cmd_opts
.add_option(
86 help="Emit completion code for zsh",
88 self
.cmd_opts
.add_option(
94 help="Emit completion code for fish",
96 self
.cmd_opts
.add_option(
102 help="Emit completion code for powershell",
105 self
.parser
.insert_option_group(0, self
.cmd_opts
)
107 def run(self
, options
: Values
, args
: List
[str]) -> int:
108 """Prints the completion code of the given shell"""
109 shells
= COMPLETION_SCRIPTS
.keys()
110 shell_options
= ["--" + shell
for shell
in sorted(shells
)]
111 if options
.shell
in shells
:
112 script
= textwrap
.dedent(
113 COMPLETION_SCRIPTS
.get(options
.shell
, "").format(prog
=get_prog())
115 print(BASE_COMPLETION
.format(script
=script
, shell
=options
.shell
))
119 "ERROR: You must pass {}\n".format(" or ".join(shell_options
))