~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shellcomplete.py

  • Committer: John Arbash Meinel
  • Date: 2006-11-10 15:38:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2129.
  • Revision ID: john@arbash-meinel.com-20061110153816-46acf76fc86a512b
use try/finally to clean up a nested progress bar during weave fetching

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):