Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/pip/_internal/commands/completion.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
1 from __future__ import absolute_import | |
2 | |
3 import sys | |
4 import textwrap | |
5 | |
6 from pip._internal.cli.base_command import Command | |
7 from pip._internal.utils.misc import get_prog | |
8 | |
9 BASE_COMPLETION = """ | |
10 # pip %(shell)s completion start%(script)s# pip %(shell)s completion end | |
11 """ | |
12 | |
13 COMPLETION_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 | |
48 class 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 ) |