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
20
20
# executable files with reasonable names.
22
22
# TODO: `help commands --all` should show hidden commands
24
from bzrlib import osutils
27
"""Bazaar -- a free distributed version-control tool
28
http://bazaar-vcs.org/
32
bzr init makes this directory a versioned branch
33
bzr branch make a copy of another branch
35
bzr add make files or directories versioned
36
bzr ignore ignore a file or pattern
37
bzr mv move or rename a versioned file
39
bzr status summarize changes in working copy
40
bzr diff show detailed diffs
42
bzr merge pull in changes from another branch
43
bzr commit save some or all changes
45
bzr log show history of changes
46
bzr check validate storage
48
bzr help init more help on e.g. init command
49
bzr help commands list all commands
56
def help(topic=None, outfile = None):
33
def help(topic=None, outfile=None):
34
"""Write the help for the specific topic to outfile"""
57
35
if outfile is None:
58
36
outfile = sys.stdout
60
outfile.write(global_help)
61
elif topic == 'commands':
62
help_commands(outfile = outfile)
41
if topic in help_topics.topic_registry:
42
txt = help_topics.topic_registry.get_detail(topic)
64
help_on_command(topic, outfile = outfile)
45
help_on_command(topic, outfile=outfile)
67
48
def command_usage(cmd_object):
113
94
raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname)
115
print >>outfile, 'usage:', command_usage(cmd_object)
96
print >>outfile, 'usage:', command_usage(cmd_object)
117
98
if cmd_object.aliases:
118
99
print >>outfile, 'aliases:',
140
121
def help_commands(outfile=None):
141
122
"""List all commands"""
125
outfile.write(_help_commands_to_text('commands'))
128
def _help_commands_to_text(topic):
129
"""Generate the help text for the list of commands"""
142
130
from bzrlib.commands import (builtin_command_names,
143
131
plugin_command_names,
134
if topic == 'hidden-commands':
147
138
names = set(builtin_command_names()) # to eliminate duplicates
148
139
names.update(plugin_command_names())
149
140
commands = ((n, get_cmd_object(n)) for n in names)
150
shown_commands = [(n, o) for n, o in commands if not o.hidden]
141
shown_commands = [(n, o) for n, o in commands if o.hidden == hidden]
151
142
max_name = max(len(n) for n, o in shown_commands)
152
143
indent = ' ' * (max_name + 1)
153
144
width = osutils.terminal_width() - 1
154
146
for cmd_name, cmd_object in sorted(shown_commands):
155
147
plugin_name = cmd_object.plugin_name()
156
148
if plugin_name is None:
167
159
lines = textwrap.wrap(helpstring, subsequent_indent=indent,
169
161
for line in lines:
170
outfile.write(line + '\n')
162
out.append(line + '\n')
166
help_topics.topic_registry.register("commands",
167
_help_commands_to_text,
168
"Basic help for all commands")
169
help_topics.topic_registry.register("hidden-commands",
170
_help_commands_to_text,
171
"All hidden commands")