142
142
from bzrlib.commands import (builtin_command_names,
143
143
plugin_command_names,
146
145
if outfile is None:
147
146
outfile = sys.stdout
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())
154
commands = [(n, get_cmd_object(n)) for n in names]
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:
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:
168
plugin_name = '<%s>' % plugin_name
159
plugin_name = ' <%s>' % plugin_name
170
161
cmd_help = cmd_object.help()
172
163
firstline = cmd_help.split('\n', 1)[0]
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,
178
169
for line in lines:
179
print >> outfile, line
170
outfile.write(line + '\n')