1
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
1
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
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
55
56
def help(topic=None, outfile = None):
57
58
outfile = sys.stdout
59
60
outfile.write(global_help)
60
61
elif topic == 'commands':
61
62
help_commands(outfile = outfile)
103
104
cmdname = str(cmdname)
106
107
outfile = sys.stdout
108
109
cmd_object = get_cmd_object(cmdname)
110
111
doc = cmd_object.help()
112
113
raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
114
115
print >>outfile, 'usage:', command_usage(cmd_object)
130
131
def help_on_command_options(cmd, outfile=None):
131
from bzrlib.option import Option
132
from bzrlib.option import Option, get_optparser
132
135
options = cmd.options()
137
outfile.write('\noptions:\n')
138
for option_name, option in sorted(options.items()):
139
l = ' --' + option_name
140
if option.type is not None:
141
l += ' ' + option.argname.upper()
142
short_name = option.short_name()
144
assert len(short_name) == 1
145
l += ', -' + short_name
146
l += (30 - len(l)) * ' ' + option.help
147
# TODO: split help over multiple lines with correct indenting and
149
wrapped = textwrap.fill(l, initial_indent='', subsequent_indent=30*' ')
150
outfile.write(wrapped + '\n')
137
outfile.write(get_optparser(options).format_option_help())
153
140
def help_commands(outfile=None):
155
142
from bzrlib.commands import (builtin_command_names,
156
143
plugin_command_names,
160
146
outfile = sys.stdout
162
names = set() # to eliminate duplicates
163
names.update(builtin_command_names())
147
names = set(builtin_command_names()) # to eliminate duplicates
164
148
names.update(plugin_command_names())
168
for cmd_name in names:
169
cmd_object = get_cmd_object(cmd_name)
170
if cmd_object.hidden:
172
print >>outfile, command_usage(cmd_object)
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):
174
155
plugin_name = cmd_object.plugin_name()
175
print_command_plugin(cmd_object, outfile, ' %s\n')
156
if plugin_name is None:
159
plugin_name = ' [%s]' % plugin_name
177
161
cmd_help = cmd_object.help()
179
163
firstline = cmd_help.split('\n', 1)[0]
180
print >>outfile, ' ' + firstline
166
helpstring = '%-*s %s%s' % (max_name, cmd_name, firstline, plugin_name)
167
lines = textwrap.wrap(helpstring, subsequent_indent=indent,
170
outfile.write(line + '\n')