~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shellcomplete.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-24 14:12:53 UTC
  • mto: This revision was merged to the branch mainline in revision 2095.
  • Revision ID: john@arbash-meinel.com-20061024141253-783fba812b197b70
(John Arbash Meinel) Update version information for 0.13 development

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
    else:
26
26
        shellcomplete_on_command(context, outfile = outfile)
27
27
 
28
 
 
29
 
def shellcomplete_on_command(cmdname, outfile=None):
 
28
def shellcomplete_on_command(cmdname, outfile = None):
30
29
    cmdname = str(cmdname)
31
30
 
32
31
    if outfile is None:
40
39
    if doc is None:
41
40
        raise NotImplementedError("sorry, no detailed shellcomplete yet for %r" % cmdname)
42
41
 
43
 
    shellcomplete_on_options(cmdobj.options().values(), outfile=outfile)
 
42
    shellcomplete_on_option(cmdobj.takes_options, outfile = None)
44
43
    for aname in cmdobj.takes_args:
45
44
        outfile.write(aname + '\n')
46
45
 
47
46
 
48
 
def shellcomplete_on_options(options, outfile=None):
49
 
    for opt in options:
50
 
        if opt.short_name:
51
 
            outfile.write('"(--%s -%s)"{--%s,-%s}\n'
52
 
                    % (opt.name, opt.short_name(), opt.name, opt.short_name()))
53
 
        else:
54
 
            outfile.write('--%s\n' % opt.name)
 
47
def shellcomplete_on_option(options, outfile=None):
 
48
    from bzrlib.option import Option
 
49
    if not options:
 
50
        return
 
51
    if outfile is None:
 
52
        outfile = sys.stdout
 
53
    for on in options:
 
54
        for shortname, longname in Option.SHORT_OPTIONS.items():
 
55
            if longname == on:
 
56
                l = '"(--' + on + ' -' + shortname + ')"{--' + on + ',-' + shortname + '}'
 
57
                break
 
58
            else:
 
59
                l = '--' + on
 
60
        outfile.write(l + '\n')
55
61
 
56
62
 
57
63
def shellcomplete_commands(outfile = None):
66
72
    cmds = []
67
73
    for cmdname, cmdclass in commands.get_all_cmds():
68
74
        cmds.append((cmdname, cmdclass))
69
 
        for alias in cmdclass.aliases:
70
 
            cmds.append((alias, cmdclass))
 
75
        for alias in cmdclass.aliases:
 
76
            cmds.append((alias, cmdclass))
71
77
    cmds.sort()
72
78
    for cmdname, cmdclass in cmds:
73
79
        if cmdclass.hidden:
74
80
            continue
75
81
        doc = getdoc(cmdclass)
76
82
        if doc is None:
77
 
            outfile.write(cmdname + '\n')
 
83
            outfile.write(cmdname + '\n')
78
84
        else:
79
 
            doclines = doc.splitlines()
80
 
            firstline = doclines[0].lower()
81
 
            outfile.write(cmdname + ':' + firstline[0:-1] + '\n')
 
85
            doclines = doc.splitlines()
 
86
            firstline = doclines[0].lower()
 
87
            outfile.write(cmdname + ':' + firstline[0:-1] + '\n')