~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Aaron Bentley
  • Date: 2006-08-08 06:47:16 UTC
  • mto: (1910.2.43 format-bumps)
  • mto: This revision was merged to the branch mainline in revision 1922.
  • Revision ID: aaron.bentley@utoronto.ca-20060808064716-75bc465292c2708f
Ensure root entry always has a revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005 by Canonical Ltd
2
 
 
 
1
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
20
# executable files with reasonable names.
21
21
 
22
22
# TODO: `help commands --all` should show hidden commands
 
23
import textwrap
23
24
 
24
25
global_help = \
25
 
"""Bazaar-NG -- a free distributed version-control tool
26
 
http://bazaar-ng.org/
27
 
 
28
 
WARNING: This is an unstable development version.
29
 
         Please keep backups.
 
26
"""Bazaar -- a free distributed version-control tool
 
27
http://bazaar-vcs.org/
30
28
 
31
29
Basic commands:
32
30
 
87
85
    return s
88
86
 
89
87
 
 
88
def print_command_plugin(cmd_object, outfile, format):
 
89
    """Print the plugin that provides a command object, if any.
 
90
 
 
91
    If the cmd_object is provided by a plugin, prints the plugin name to
 
92
    outfile using the provided format string.
 
93
    """
 
94
    plugin_name = cmd_object.plugin_name()
 
95
    if plugin_name is not None:
 
96
        out_str = '(From plugin "%s")' % plugin_name
 
97
        outfile.write(format % out_str)
 
98
 
 
99
 
90
100
def help_on_command(cmdname, outfile=None):
91
101
    from bzrlib.commands import get_cmd_object
92
102
 
109
119
 
110
120
    print >>outfile
111
121
 
 
122
    print_command_plugin(cmd_object, outfile, '%s\n\n')
 
123
 
112
124
    outfile.write(doc)
113
125
    if doc[-1] != '\n':
114
126
        outfile.write('\n')
115
 
    help_on_command_options(cmd_object, outfile=None)
 
127
    help_on_command_options(cmd_object, outfile)
116
128
 
117
129
 
118
130
def help_on_command_options(cmd, outfile=None):
130
142
        short_name = option.short_name()
131
143
        if short_name:
132
144
            assert len(short_name) == 1
133
 
            l += ', -' + shortname
 
145
            l += ', -' + short_name
134
146
        l += (30 - len(l)) * ' ' + option.help
135
147
        # TODO: split help over multiple lines with correct indenting and 
136
148
        # wrapping
137
 
        outfile.write(l + '\n')
 
149
        wrapped = textwrap.fill(l, initial_indent='', subsequent_indent=30*' ')
 
150
        outfile.write(wrapped + '\n')
138
151
 
139
152
 
140
153
def help_commands(outfile=None):
157
170
        if cmd_object.hidden:
158
171
            continue
159
172
        print >>outfile, command_usage(cmd_object)
 
173
 
 
174
        plugin_name = cmd_object.plugin_name()
 
175
        print_command_plugin(cmd_object, outfile, '        %s\n')
 
176
 
160
177
        cmd_help = cmd_object.help()
161
178
        if cmd_help:
162
179
            firstline = cmd_help.split('\n', 1)[0]
163
 
            print >>outfile, '    ' + firstline
 
180
            print >>outfile, '        ' + firstline
164
181