Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/pip/commands/completion.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author | bcclaywell |
---|---|
date | Mon, 12 Oct 2015 17:43:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d67268158946 |
---|---|
1 from __future__ import absolute_import | |
2 | |
3 import sys | |
4 from pip.basecommand import Command | |
5 | |
6 BASE_COMPLETION = """ | |
7 # pip %(shell)s completion start%(script)s# pip %(shell)s completion end | |
8 """ | |
9 | |
10 COMPLETION_SCRIPTS = { | |
11 'bash': """ | |
12 _pip_completion() | |
13 { | |
14 COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \\ | |
15 COMP_CWORD=$COMP_CWORD \\ | |
16 PIP_AUTO_COMPLETE=1 $1 ) ) | |
17 } | |
18 complete -o default -F _pip_completion pip | |
19 """, 'zsh': """ | |
20 function _pip_completion { | |
21 local words cword | |
22 read -Ac words | |
23 read -cn cword | |
24 reply=( $( COMP_WORDS="$words[*]" \\ | |
25 COMP_CWORD=$(( cword-1 )) \\ | |
26 PIP_AUTO_COMPLETE=1 $words[1] ) ) | |
27 } | |
28 compctl -K _pip_completion pip | |
29 """} | |
30 | |
31 | |
32 class CompletionCommand(Command): | |
33 """A helper command to be used for command completion.""" | |
34 name = 'completion' | |
35 summary = 'A helper command to be used for command completion' | |
36 hidden = True | |
37 | |
38 def __init__(self, *args, **kw): | |
39 super(CompletionCommand, self).__init__(*args, **kw) | |
40 | |
41 cmd_opts = self.cmd_opts | |
42 | |
43 cmd_opts.add_option( | |
44 '--bash', '-b', | |
45 action='store_const', | |
46 const='bash', | |
47 dest='shell', | |
48 help='Emit completion code for bash') | |
49 cmd_opts.add_option( | |
50 '--zsh', '-z', | |
51 action='store_const', | |
52 const='zsh', | |
53 dest='shell', | |
54 help='Emit completion code for zsh') | |
55 | |
56 self.parser.insert_option_group(0, cmd_opts) | |
57 | |
58 def run(self, options, args): | |
59 """Prints the completion code of the given shell""" | |
60 shells = COMPLETION_SCRIPTS.keys() | |
61 shell_options = ['--' + shell for shell in sorted(shells)] | |
62 if options.shell in shells: | |
63 script = COMPLETION_SCRIPTS.get(options.shell, '') | |
64 print(BASE_COMPLETION % {'script': script, 'shell': options.shell}) | |
65 else: | |
66 sys.stderr.write( | |
67 'ERROR: You must pass %s\n' % ' or '.join(shell_options) | |
68 ) |