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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""bzr-infogen.py - generate information from built-in bzr help
21
bzr-infogen.py creates a file with information on bzr in one of
22
several different output formats:
25
bash_completion bash completion script
28
Run "bzr-infogen.py --help" for usage information.
31
# Plan (devised by jblack and ndim 2005-12-10):
32
# * one bzr-infogen.py script in top level dir right beside bzr
33
# * one bzrinfogen/ directory (python module)
34
# We did not put the stuff into bzrlib/infogen/ because we thought
35
# that all this stuff doesn't need to get loaded every time you run bzr.
36
# However, I'm not sure that is actually true (ndim 2005-12-11).
37
# * several generator scripts like
38
# bzrinfogen/gen_man_page.py
41
# gen_bash_completion.py
42
# gen_zsh_completion.py
43
# * scripts are called by running something like
44
# "bzr-infogen.py --man-page" or "bzr-infogen.py --bash-completion"
45
# * one test case which iterates through all gen_*.py scripts and
46
# tries to generate all the file types, checking that all generators
47
# work (we'll let bzrinfogen/__init__.py provide the list to walk through)
48
# * those generator scripts walk through the command and option data
49
# structures to extract the required information
50
# * the actual names are just prototypes and subject to change
58
from optparse import OptionParser
59
parser = OptionParser(usage="%prog [options] OUTPUT_FORMAT")
60
parser.add_option("-s", "--show-filename",
61
action="store_true", dest="show_filename", default=False,
62
help="print default filename on stdout")
63
parser.add_option("-o", "--output", dest="filename",
64
help="write output to FILE", metavar="FILE")
65
parser.add_option("-b", "--bzr-name", dest="bzr_name", default="bzr",
66
help="name of bzr executable", metavar="EXEC_NAME")
67
parser.add_option("-q", "--quiet",
68
action="store_false", dest="verbose", default=True,
69
help="don't print status messages to stdout")
70
(options, args) = parser.parse_args(argv)
73
parser.error("incorrect number of arguments")
75
infogen_type = args[1]
76
infogen_mod = bzrinfogen.get_infogen_mod(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
print >>sys.stdout, outfilename
91
infogen_mod.infogen(options, outfile)
94
if __name__ == '__main__':