cli: Use list of options shared between commands
authorMichael Hanselmann <hansmi@google.com>
Tue, 7 Sep 2010 09:44:26 +0000 (11:44 +0200)
committerMichael Hanselmann <hansmi@google.com>
Tue, 7 Sep 2010 09:44:54 +0000 (11:44 +0200)
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: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

autotools/build-bash-completion
lib/cli.py

index bcb1239..efb381f 100755 (executable)
@@ -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", {})
index 83c288f..922ce81 100644 (file)
@@ -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))