4
def shellcomplete(context=None, outfile = None):
8
shellcomplete_commands(outfile = outfile)
10
shellcomplete_on_command(context, outfile = outfile)
12
def shellcomplete_on_command(cmdname, outfile = None):
13
cmdname = str(cmdname)
18
from inspect import getdoc
20
cmdobj = commands.get_cmd_object(cmdname)
24
raise NotImplementedError("sorry, no detailed shellcomplete yet for %r" % cmdname)
26
shellcomplete_on_option(cmdobj.takes_options, outfile = None)
27
for aname in cmdobj.takes_args:
28
outfile.write(aname + '\n')
31
def shellcomplete_on_option(options, outfile = None):
41
for shortname, longname in commands.SHORT_OPTIONS.items():
43
l = '"(--' + on + ' -' + shortname + ')"{--' + on + ',-' + shortname + '}'
47
outfile.write(l + '\n')
50
def shellcomplete_commands(outfile = None):
51
"""List all commands"""
54
from inspect import getdoc
60
for cmdname, cmdclass in commands.get_all_cmds():
61
cmds.append((cmdname, cmdclass))
62
for alias in cmdclass.aliases:
63
cmds.append((alias, cmdclass))
65
for cmdname, cmdclass in cmds:
68
doc = getdoc(cmdclass)
70
outfile.write(cmdname + '\n')
72
doclines = doc.splitlines()
73
firstline = doclines[0].lower()
74
outfile.write(cmdname + ':' + firstline[0:-1] + '\n')