1
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
1
# Copyright (C) 2004, 2005, 2006 by 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
56
55
def help(topic=None, outfile = None):
58
57
outfile = sys.stdout
60
59
outfile.write(global_help)
61
60
elif topic == 'commands':
62
61
help_commands(outfile = outfile)
104
103
cmdname = str(cmdname)
107
106
outfile = sys.stdout
109
108
cmd_object = get_cmd_object(cmdname)
111
110
doc = cmd_object.help()
113
112
raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
115
114
print >>outfile, 'usage:', command_usage(cmd_object)
131
130
def help_on_command_options(cmd, outfile=None):
132
from bzrlib.option import Option, get_optparser
131
from bzrlib.option import Option
135
132
options = cmd.options()
137
outfile.write(get_optparser(options).format_option_help())
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')
140
153
def help_commands(outfile=None):
142
155
from bzrlib.commands import (builtin_command_names,
143
156
plugin_command_names,
146
160
outfile = sys.stdout
147
names = set(builtin_command_names()) # to eliminate duplicates
162
names = set() # to eliminate duplicates
163
names.update(builtin_command_names())
148
164
names.update(plugin_command_names())
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):
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)
155
174
plugin_name = cmd_object.plugin_name()
156
if plugin_name is None:
159
plugin_name = ' [%s]' % plugin_name
175
print_command_plugin(cmd_object, outfile, ' %s\n')
161
177
cmd_help = cmd_object.help()
163
179
firstline = cmd_help.split('\n', 1)[0]
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')
180
print >>outfile, ' ' + firstline