bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1692.7.3
by Martin Pool
Remove backup warning from bzr help |
1 |
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
|
351
by Martin Pool
- Split out help functions into bzrlib.help |
3 |
# This program is free software; you can redistribute it and/or modify
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
|
351
by Martin Pool
- Split out help functions into bzrlib.help |
8 |
# This program is distributed in the hope that it will be useful,
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
|
351
by Martin Pool
- Split out help functions into bzrlib.help |
13 |
# You should have received a copy of the GNU General Public License
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
|
1162
by Martin Pool
- change Command infrastructure to use (mostly stateless) objects to |
17 |
# TODO: Some way to get a list of external commands (defined by shell
|
18 |
# scripts) so that they can be included in the help listing as well.
|
|
19 |
# It should be enough to just list the plugin directory and look for
|
|
20 |
# executable files with reasonable names.
|
|
21 |
||
22 |
# TODO: `help commands --all` should show hidden commands
|
|
|
351
by Martin Pool
- Split out help functions into bzrlib.help |
23 |
|
|
635
by Martin Pool
- manpage generator by Hans Ulrich Niedermann |
24 |
import sys |
|
1993.4.4
by John Arbash Meinel
cleanup help.py |
25 |
|
26 |
from bzrlib import help_topics |
|
27 |
||
28 |
||
29 |
help_topics.add_topic("commands", |
|
30 |
(lambda name, outfile: help_commands(outfile)), |
|
31 |
"Basic help for all commands") |
|
32 |
||
33 |
||
34 |
def help(topic=None, outfile=None): |
|
|
1993.4.5
by John Arbash Meinel
Add some basic smoke tests for help topics |
35 |
"""Print out the help for a specific topic or command.""" |
36 |
||
|
1993.4.4
by John Arbash Meinel
cleanup help.py |
37 |
if outfile is None: |
|
635
by Martin Pool
- manpage generator by Hans Ulrich Niedermann |
38 |
outfile = sys.stdout |
|
1993.4.4
by John Arbash Meinel
cleanup help.py |
39 |
if topic is None: |
40 |
help_topics.write_topic("basic", outfile) |
|
41 |
elif help_topics.is_topic(topic): |
|
42 |
help_topics.write_topic(topic, outfile) |
|
|
351
by Martin Pool
- Split out help functions into bzrlib.help |
43 |
else: |
|
1993.4.4
by John Arbash Meinel
cleanup help.py |
44 |
help_on_command(topic, outfile=outfile) |
|
351
by Martin Pool
- Split out help functions into bzrlib.help |
45 |
|
46 |
||
|
1162
by Martin Pool
- change Command infrastructure to use (mostly stateless) objects to |
47 |
def command_usage(cmd_object): |
|
452
by Martin Pool
- show command usage in help |
48 |
"""Return single-line grammar for command. |
49 |
||
50 |
Only describes arguments, not options.
|
|
51 |
"""
|
|
|
1177
by Martin Pool
- help on command says "usage: bzr help" |
52 |
s = 'bzr ' + cmd_object.name() + ' ' |
|
1162
by Martin Pool
- change Command infrastructure to use (mostly stateless) objects to |
53 |
for aname in cmd_object.takes_args: |
|
452
by Martin Pool
- show command usage in help |
54 |
aname = aname.upper() |
55 |
if aname[-1] in ['$', '+']: |
|
56 |
aname = aname[:-1] + '...' |
|
57 |
elif aname[-1] == '?': |
|
58 |
aname = '[' + aname[:-1] + ']' |
|
59 |
elif aname[-1] == '*': |
|
60 |
aname = '[' + aname[:-1] + '...]' |
|
61 |
s += aname + ' ' |
|
62 |
||
63 |
assert s[-1] == ' ' |
|
64 |
s = s[:-1] |
|
65 |
||
66 |
return s |
|
67 |
||
68 |
||
|
1733.2.5
by Michael Ellerman
Show which plugin (if any) provides a command. |
69 |
def print_command_plugin(cmd_object, outfile, format): |
70 |
"""Print the plugin that provides a command object, if any. |
|
71 |
||
72 |
If the cmd_object is provided by a plugin, prints the plugin name to
|
|
73 |
outfile using the provided format string.
|
|
74 |
"""
|
|
75 |
plugin_name = cmd_object.plugin_name() |
|
76 |
if plugin_name is not None: |
|
77 |
out_str = '(From plugin "%s")' % plugin_name |
|
78 |
outfile.write(format % out_str) |
|
79 |
||
80 |
||
|
1162
by Martin Pool
- change Command infrastructure to use (mostly stateless) objects to |
81 |
def help_on_command(cmdname, outfile=None): |
82 |
from bzrlib.commands import get_cmd_object |
|
83 |
||
|
351
by Martin Pool
- Split out help functions into bzrlib.help |
84 |
cmdname = str(cmdname) |
85 |
||
|
635
by Martin Pool
- manpage generator by Hans Ulrich Niedermann |
86 |
if outfile == None: |
87 |
outfile = sys.stdout |
|
88 |
||
|
1162
by Martin Pool
- change Command infrastructure to use (mostly stateless) objects to |
89 |
cmd_object = get_cmd_object(cmdname) |
|
351
by Martin Pool
- Split out help functions into bzrlib.help |
90 |
|
|
1162
by Martin Pool
- change Command infrastructure to use (mostly stateless) objects to |
91 |
doc = cmd_object.help() |
|
351
by Martin Pool
- Split out help functions into bzrlib.help |
92 |
if doc == None: |
93 |
raise NotImplementedError("sorry, no detailed help yet for %r" % cmdname) |
|
94 |
||
|
1162
by Martin Pool
- change Command infrastructure to use (mostly stateless) objects to |
95 |
print >>outfile, 'usage:', command_usage(cmd_object) |
96 |
||
97 |
if cmd_object.aliases: |
|
98 |
print >>outfile, 'aliases:', |
|
99 |
print >>outfile, ', '.join(cmd_object.aliases) |
|
100 |
||
101 |
print >>outfile |
|
102 |
||
|
1733.2.5
by Michael Ellerman
Show which plugin (if any) provides a command. |
103 |
print_command_plugin(cmd_object, outfile, '%s\n\n') |
104 |
||
|
635
by Martin Pool
- manpage generator by Hans Ulrich Niedermann |
105 |
outfile.write(doc) |
|
675
by Martin Pool
- help formatting fix from ndim |
106 |
if doc[-1] != '\n': |
107 |
outfile.write('\n') |
|
|
1185.33.15
by Martin Pool
[path] bgu in help_on_command (Robert Widhopf-Frank) |
108 |
help_on_command_options(cmd_object, outfile) |
|
1185.16.43
by Martin Pool
- clean up handling of option objects |
109 |
|
110 |
||
111 |
def help_on_command_options(cmd, outfile=None): |
|
|
1857.1.3
by Aaron Bentley
Make option adding depend on Option type |
112 |
from bzrlib.option import Option, get_optparser |
|
1857.1.2
by Aaron Bentley
Use optparse for generating option help |
113 |
if outfile is None: |
114 |
outfile = sys.stdout |
|
|
1185.16.43
by Martin Pool
- clean up handling of option objects |
115 |
options = cmd.options() |
|
1857.1.2
by Aaron Bentley
Use optparse for generating option help |
116 |
outfile.write('\n') |
117 |
outfile.write(get_optparser(options).format_option_help()) |
|
|
635
by Martin Pool
- manpage generator by Hans Ulrich Niedermann |
118 |
|
119 |
||
|
1162
by Martin Pool
- change Command infrastructure to use (mostly stateless) objects to |
120 |
def help_commands(outfile=None): |
|
351
by Martin Pool
- Split out help functions into bzrlib.help |
121 |
"""List all commands""" |
|
1162
by Martin Pool
- change Command infrastructure to use (mostly stateless) objects to |
122 |
from bzrlib.commands import (builtin_command_names, |
123 |
plugin_command_names, |
|
124 |
get_cmd_object) |
|
|
635
by Martin Pool
- manpage generator by Hans Ulrich Niedermann |
125 |
|
126 |
if outfile == None: |
|
127 |
outfile = sys.stdout |
|
|
1162
by Martin Pool
- change Command infrastructure to use (mostly stateless) objects to |
128 |
|
129 |
names = set() # to eliminate duplicates |
|
130 |
names.update(builtin_command_names()) |
|
131 |
names.update(plugin_command_names()) |
|
132 |
names = list(names) |
|
133 |
names.sort() |
|
134 |
||
135 |
for cmd_name in names: |
|
136 |
cmd_object = get_cmd_object(cmd_name) |
|
137 |
if cmd_object.hidden: |
|
|
351
by Martin Pool
- Split out help functions into bzrlib.help |
138 |
continue
|
|
1162
by Martin Pool
- change Command infrastructure to use (mostly stateless) objects to |
139 |
print >>outfile, command_usage(cmd_object) |
|
1733.2.5
by Michael Ellerman
Show which plugin (if any) provides a command. |
140 |
|
141 |
plugin_name = cmd_object.plugin_name() |
|
142 |
print_command_plugin(cmd_object, outfile, ' %s\n') |
|
143 |
||
|
1162
by Martin Pool
- change Command infrastructure to use (mostly stateless) objects to |
144 |
cmd_help = cmd_object.help() |
145 |
if cmd_help: |
|
146 |
firstline = cmd_help.split('\n', 1)[0] |
|
|
1553.5.4
by Martin Pool
[patch] better formatting for 'bzr help commands' (Matthew D Fuller) |
147 |
print >>outfile, ' ' + firstline |
|
1993.4.1
by John Arbash Meinel
Goffredo Baroncelli: add help topics |
148 |