~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shellcomplete.py

  • Committer: Martin Pool
  • Date: 2006-12-15 08:36:50 UTC
  • mto: (2193.3.1 short-options)
  • mto: This revision was merged to the branch mainline in revision 2203.
  • Revision ID: mbp@sourcefrog.net-20061215083650-14cbsfiijfq3kdf9
remove global registration of short options

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
 
def shellcomplete_on_command(cmdname, outfile = None):
 
28
 
 
29
def shellcomplete_on_command(cmdname, outfile=None):
29
30
    cmdname = str(cmdname)
30
31
 
31
32
    if outfile is None:
39
40
    if doc is None:
40
41
        raise NotImplementedError("sorry, no detailed shellcomplete yet for %r" % cmdname)
41
42
 
42
 
    shellcomplete_on_option(cmdobj.takes_options, outfile = None)
 
43
    shellcomplete_on_options(cmdobj.options().values(), outfile=outfile)
43
44
    for aname in cmdobj.takes_args:
44
45
        outfile.write(aname + '\n')
45
46
 
46
47
 
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')
 
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)
61
55
 
62
56
 
63
57
def shellcomplete_commands(outfile = None):