~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/help.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-25 22:20:37 UTC
  • mfrom: (2034.1.6 helptext)
  • Revision ID: pqm@pqm.ubuntu.com-20060925222037-8be906e237613b10
Condense help command listings

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
# TODO: `help commands --all` should show hidden commands
23
23
import textwrap
 
24
from bzrlib import osutils 
24
25
 
25
26
global_help = \
26
27
"""Bazaar -- a free distributed version-control tool
141
142
    from bzrlib.commands import (builtin_command_names,
142
143
                                 plugin_command_names,
143
144
                                 get_cmd_object)
144
 
 
145
145
    if outfile is None:
146
146
        outfile = sys.stdout
147
 
 
148
 
    names = set()                       # to eliminate duplicates
149
 
    names.update(builtin_command_names())
 
147
    names = set(builtin_command_names()) # to eliminate duplicates
150
148
    names.update(plugin_command_names())
151
 
    names = list(names)
152
 
    names.sort()
153
 
 
154
 
    for cmd_name in names:
155
 
        cmd_object = get_cmd_object(cmd_name)
156
 
        if cmd_object.hidden:
157
 
            continue
158
 
        print >>outfile, command_usage(cmd_object)
159
 
 
 
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)
 
153
    width = osutils.terminal_width() - 1
 
154
    for cmd_name, cmd_object in sorted(shown_commands):
160
155
        plugin_name = cmd_object.plugin_name()
161
 
        print_command_plugin(cmd_object, outfile, '        %s\n')
 
156
        if plugin_name is None:
 
157
            plugin_name = ''
 
158
        else:
 
159
            plugin_name = ' [%s]' % plugin_name
162
160
 
163
161
        cmd_help = cmd_object.help()
164
162
        if cmd_help:
165
163
            firstline = cmd_help.split('\n', 1)[0]
166
 
            print >>outfile, '        ' + firstline
167
 
        
 
164
        else:
 
165
            firstline = ''
 
166
        helpstring = '%-*s %s%s' % (max_name, cmd_name, firstline, plugin_name)
 
167
        lines = textwrap.wrap(helpstring, subsequent_indent=indent,
 
168
                              width=width)
 
169
        for line in lines:
 
170
            outfile.write(line + '\n')