]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/CLI.py
Modified the default_option_parser function to return a parser using a VerbatimHelpFo...
[dead/census-tools.git] / src / CLI.py
1 from optparse import IndentedHelpFormatter
2 from optparse import OptionParser
3
4 import Configuration.Defaults
5
6
7 def default_option_parser(usage=None):
8 # Use a VerbatimFormatter instead of the default
9 # IndentedHelpFormatter.
10 fmtr = VerbatimHelpFormatter()
11
12 # -h (help) Conflicts with -h HOSTNAME
13 parser = OptionParser(usage = usage,
14 add_help_option = False,
15 formatter = fmtr)
16
17 parser.add_option('-h',
18 '--host',
19 help='The hostname/address where the database is located.',
20 default=Configuration.Defaults.DATABASE_HOST)
21
22 parser.add_option('-d',
23 '--database',
24 help='The database in which the population data are stored.',
25 default=Configuration.Defaults.DATABASE_NAME)
26
27 parser.add_option('-U',
28 '--username',
29 help='The username who has access to the database.',
30 default=Configuration.Defaults.DATABASE_USERNAME)
31
32 return parser
33
34
35
36 class VerbatimHelpFormatter(IndentedHelpFormatter):
37 """
38 The two HelpFormatters supplied with OptParse like to mangle their
39 descriptions during print_help(). This subclassed formatter
40 overrides the format_description() method with an implementation
41 that simply returns the description unmodified.
42 """
43 def format_description(self, description):
44 return description