~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Aaron Bentley
  • Date: 2006-09-24 16:03:38 UTC
  • mto: This revision was merged to the branch mainline in revision 2042.
  • Revision ID: aaron.bentley@utoronto.ca-20060924160338-24efe2f89e6cc190
Changes from review and tweaks

Show diffs side-by-side

added added

removed removed

Lines of Context:
142
142
    from bzrlib.commands import (builtin_command_names,
143
143
                                 plugin_command_names,
144
144
                                 get_cmd_object)
145
 
 
146
145
    if outfile is None:
147
146
        outfile = sys.stdout
148
 
 
149
 
    names = set()                       # to eliminate duplicates
150
 
    names.update(builtin_command_names())
 
147
    names = set(builtin_command_names()) # to eliminate duplicates
151
148
    names.update(plugin_command_names())
152
 
    names = list(names)
153
 
    names.sort()
154
 
    commands = [(n, get_cmd_object(n)) for n in names]
155
 
 
156
 
    max_name = max([len(n) for n, o in commands if not o.hidden])
157
 
    format_string = '%%-%ds %%s %%s' % max_name
158
 
    indent = ' ' * (max_name+1)
 
149
    commands = ((n, get_cmd_object(n)) for n in names)
 
150
    shown_commands = [(n, o) for n, o in commands if not o.hidden]
 
151
    max_name = max(len(n) for n, o in shown_commands)
 
152
    indent = ' ' * (max_name + 1)
159
153
    width = osutils.terminal_width() - 1
160
 
    for cmd_name in names:
161
 
        cmd_object = get_cmd_object(cmd_name)
162
 
        if cmd_object.hidden:
163
 
            continue
 
154
    for cmd_name, cmd_object in sorted(shown_commands):
164
155
        plugin_name = cmd_object.plugin_name()
165
156
        if plugin_name is None:
166
157
            plugin_name = ''
167
158
        else:
168
 
            plugin_name = '<%s>' % plugin_name
 
159
            plugin_name = ' <%s>' % plugin_name
169
160
 
170
161
        cmd_help = cmd_object.help()
171
162
        if cmd_help:
172
163
            firstline = cmd_help.split('\n', 1)[0]
173
164
        else:
174
165
            firstline = ''
175
 
        helpstring = format_string % (cmd_name, firstline, plugin_name)
 
166
        helpstring = '%-*s %s%s' % (max_name, cmd_name, firstline, plugin_name)
176
167
        lines = textwrap.wrap(helpstring, subsequent_indent=indent,
177
168
                              width=width)
178
169
        for line in lines:
179
 
            print >> outfile, line
180
 
        
 
170
            outfile.write(line + '\n')