/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/shellcomplete.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-11-08 07:44:30 UTC
  • mfrom: (2123 +trunk)
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061108074430-a9c08d4a475bd97f
Merge bzr.dev

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():
39
55
            if longname == on:
40
56
                l = '"(--' + on + ' -' + shortname + ')"{--' + on + ',-' + shortname + '}'
41
57
                break
42
 
            else:
43
 
                l = '--' + on
 
58
            else:
 
59
                l = '--' + on
44
60
        outfile.write(l + '\n')
45
61
 
46
62
 
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 = []
57
73
    for cmdname, cmdclass in commands.get_all_cmds():
58
74
        cmds.append((cmdname, cmdclass))
59
 
        for alias in cmdclass.aliases:
60
 
            cmds.append((alias, cmdclass))
 
75
        for alias in cmdclass.aliases:
 
76
            cmds.append((alias, cmdclass))
61
77
    cmds.sort()
62
78
    for cmdname, cmdclass in cmds:
63
79
        if cmdclass.hidden:
64
80
            continue
65
81
        doc = getdoc(cmdclass)
66
 
        if doc == None:
67
 
            outfile.write(cmdname + '\n')
 
82
        if doc is None:
 
83
            outfile.write(cmdname + '\n')
68
84
        else:
69
 
            doclines = doc.splitlines()
70
 
            firstline = doclines[0].lower()
71
 
            outfile.write(cmdname + ':' + firstline[0:-1] + '\n')
 
85
            doclines = doc.splitlines()
 
86
            firstline = doclines[0].lower()
 
87
            outfile.write(cmdname + ':' + firstline[0:-1] + '\n')