3
# Copyright 2005 Canonical Ltd.
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
"""%(prog)s - generate information from built-in bzr help
21
%(prog)s creates a file with information on bzr in one of
22
several different output formats:
25
bash_completion bash completion script
30
python2.4 generated-docs.py man
31
python2.4 generated-docs.py bash_completion
33
Run "%(prog)s --help" for the option reference.
36
import bzrlib.commands
38
from optparse import OptionParser
40
import tools.doc_generate
43
parser = OptionParser(usage="""%prog [options] OUTPUT_FORMAT
45
Available OUTPUT_FORMAT:
48
rstx man page in ReStructuredText format
49
bash_completion bash completion script""")
51
parser.add_option("-s", "--show-filename",
52
action="store_true", dest="show_filename", default=False,
53
help="print default filename on stdout")
55
parser.add_option("-o", "--output", dest="filename", metavar="FILE",
56
help="write output to FILE")
58
parser.add_option("-b", "--bzr-name",
59
dest="bzr_name", default="bzr", metavar="EXEC_NAME",
60
help="name of bzr executable")
62
parser.add_option("-e", "--examples",
63
action="callback", callback=print_extended_help,
64
help="Examples of ways to call generate_doc")
67
(options, args) = parser.parse_args(argv)
73
bzrlib.commands.install_bzr_command_hooks()
75
infogen_type = args[1]
76
infogen_mod = tools.doc_generate.get_module(infogen_type)
79
outfilename = options.filename
81
outfilename = infogen_mod.get_filename(options)
83
if outfilename == "-":
86
outfile = open(outfilename,"w")
88
if options.show_filename and (outfilename != "-"):
89
sys.stdout.write(outfilename)
90
sys.stdout.write('\n')
92
infogen_mod.infogen(options, outfile)
94
def print_extended_help(option, opt, value, parser):
95
""" Program help examples
97
Prints out the examples stored in the docstring.
100
sys.stdout.write(__doc__ % {"prog":sys.argv[0]})
101
sys.stdout.write('\n')
104
if __name__ == '__main__':