Commit 5786c087 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

cli: Use list of options shared between commands



The completion script for bash has to know about these options. Until now
the list was in two places--once in cli.py and once in
autotools/build-bash-completion. A shared list is used with this patch.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 6760e4ed
......@@ -575,11 +575,14 @@ def GetCommands(filename, module):
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", {})
......
......@@ -1029,6 +1029,9 @@ NODRBD_STORAGE_OPT = cli_option("--no-drbd-storage", dest="drbd_storage",
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.
......@@ -1096,7 +1099,7 @@ def _ParseArgs(argv, commands, aliases):
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))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment