help_option = cli.cli_option("-h", "--help", default=False,
action="store_true")
- for (_, _, optdef, _, _) in commands.itervalues():
+ for name, (_, _, optdef, _, _) in commands.items():
if help_option not in optdef:
optdef.append(help_option)
- if cli.DEBUG_OPT not in optdef:
- optdef.append(cli.DEBUG_OPT)
+ for opt in cli.COMMON_OPTS:
+ if opt in optdef:
+ raise Exception("Common option '%s' listed for command '%s' in %s" %
+ (opt, name, filename))
+ optdef.append(opt)
# Use aliases
aliases = getattr(module, "aliases", {})
action="store_false", default=True,
help="Disable support for DRBD")
+#: Options provided by all commands
+COMMON_OPTS = [DEBUG_OPT]
+
def _ParseArgs(argv, commands, aliases):
"""Parser for the command line arguments.
cmd = aliases[cmd]
func, args_def, parser_opts, usage, description = commands[cmd]
- parser = OptionParser(option_list=parser_opts + [DEBUG_OPT],
+ parser = OptionParser(option_list=parser_opts + COMMON_OPTS,
description=description,
formatter=TitledHelpFormatter(),
usage="%%prog %s %s" % (cmd, usage))