summaryrefslogtreecommitdiff
path: root/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/completion.py
diff options
context:
space:
mode:
authorShubham Saini <shubham6405@gmail.com>2018-12-11 10:01:23 +0000
committerShubham Saini <shubham6405@gmail.com>2018-12-11 10:01:23 +0000
commit68df54d6629ec019142eb149dd037774f2d11e7c (patch)
tree345bc22d46b4e01a4ba8303b94278952a4ed2b9e /venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/completion.py
First commit
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/completion.py')
-rw-r--r--venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/completion.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/completion.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/completion.py
new file mode 100644
index 0000000..8da1e83
--- /dev/null
+++ b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/commands/completion.py
@@ -0,0 +1,94 @@
1from __future__ import absolute_import
2
3import sys
4import textwrap
5
6from pip._internal.basecommand import Command
7from pip._internal.utils.misc import get_prog
8
9BASE_COMPLETION = """
10# pip %(shell)s completion start%(script)s# pip %(shell)s completion end
11"""
12
13COMPLETION_SCRIPTS = {
14 'bash': """
15 _pip_completion()
16 {
17 COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \\
18 COMP_CWORD=$COMP_CWORD \\
19 PIP_AUTO_COMPLETE=1 $1 ) )
20 }
21 complete -o default -F _pip_completion %(prog)s
22 """,
23 'zsh': """
24 function _pip_completion {
25 local words cword
26 read -Ac words
27 read -cn cword
28 reply=( $( COMP_WORDS="$words[*]" \\
29 COMP_CWORD=$(( cword-1 )) \\
30 PIP_AUTO_COMPLETE=1 $words[1] ) )
31 }
32 compctl -K _pip_completion %(prog)s
33 """,
34 'fish': """
35 function __fish_complete_pip
36 set -lx COMP_WORDS (commandline -o) ""
37 set -lx COMP_CWORD ( \\
38 math (contains -i -- (commandline -t) $COMP_WORDS)-1 \\
39 )
40 set -lx PIP_AUTO_COMPLETE 1
41 string split \\ -- (eval $COMP_WORDS[1])
42 end
43 complete -fa "(__fish_complete_pip)" -c %(prog)s
44 """,
45}
46
47
48class CompletionCommand(Command):
49 """A helper command to be used for command completion."""
50 name = 'completion'
51 summary = 'A helper command used for command completion.'
52 ignore_require_venv = True
53
54 def __init__(self, *args, **kw):
55 super(CompletionCommand, self).__init__(*args, **kw)
56
57 cmd_opts = self.cmd_opts
58
59 cmd_opts.add_option(
60 '--bash', '-b',
61 action='store_const',
62 const='bash',
63 dest='shell',
64 help='Emit completion code for bash')
65 cmd_opts.add_option(
66 '--zsh', '-z',
67 action='store_const',
68 const='zsh',
69 dest='shell',
70 help='Emit completion code for zsh')
71 cmd_opts.add_option(
72 '--fish', '-f',
73 action='store_const',
74 const='fish',
75 dest='shell',
76 help='Emit completion code for fish')
77
78 self.parser.insert_option_group(0, cmd_opts)
79
80 def run(self, options, args):
81 """Prints the completion code of the given shell"""
82 shells = COMPLETION_SCRIPTS.keys()
83 shell_options = ['--' + shell for shell in sorted(shells)]
84 if options.shell in shells:
85 script = textwrap.dedent(
86 COMPLETION_SCRIPTS.get(options.shell, '') % {
87 'prog': get_prog(),
88 }
89 )
90 print(BASE_COMPLETION % {'script': script, 'shell': options.shell})
91 else:
92 sys.stderr.write(
93 'ERROR: You must pass %s\n' % ' or '.join(shell_options)
94 )