~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shellcomplete.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-11-02 08:06:11 UTC
  • mfrom: (2095.4.6 test-progress)
  • Revision ID: pqm@pqm.ubuntu.com-20061102080611-5462d2713bf4bc45
(mbp) Better test progress bar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
1
17
import sys
2
18
 
3
19
 
4
20
def shellcomplete(context=None, outfile = None):
5
 
    if outfile == None:
 
21
    if outfile is None:
6
22
        outfile = sys.stdout
7
 
    if context == None:
 
23
    if context is None:
8
24
        shellcomplete_commands(outfile = outfile)
9
25
    else:
10
26
        shellcomplete_on_command(context, outfile = outfile)
12
28
def shellcomplete_on_command(cmdname, outfile = None):
13
29
    cmdname = str(cmdname)
14
30
 
15
 
    if outfile == None:
 
31
    if outfile is None:
16
32
        outfile = sys.stdout
17
33
 
18
34
    from inspect import getdoc
20
36
    cmdobj = commands.get_cmd_object(cmdname)
21
37
 
22
38
    doc = getdoc(cmdobj)
23
 
    if doc == None:
 
39
    if doc is None:
24
40
        raise NotImplementedError("sorry, no detailed shellcomplete yet for %r" % cmdname)
25
41
 
26
42
    shellcomplete_on_option(cmdobj.takes_options, outfile = None)
32
48
    from bzrlib.option import Option
33
49
    if not options:
34
50
        return
35
 
    if outfile == None:
 
51
    if outfile is None:
36
52
        outfile = sys.stdout
37
53
    for on in options:
38
54
        for shortname, longname in Option.SHORT_OPTIONS.items():
50
66
    import commands
51
67
    from inspect import getdoc
52
68
    
53
 
    if outfile == None:
 
69
    if outfile is None:
54
70
        outfile = sys.stdout
55
71
    
56
72
    cmds = []
63
79
        if cmdclass.hidden:
64
80
            continue
65
81
        doc = getdoc(cmdclass)
66
 
        if doc == None:
 
82
        if doc is None:
67
83
            outfile.write(cmdname + '\n')
68
84
        else:
69
85
            doclines = doc.splitlines()