Check option name format when building bash completion
authorMichael Hanselmann <hansmi@google.com>
Wed, 17 Aug 2011 10:02:12 +0000 (12:02 +0200)
committerMichael Hanselmann <hansmi@google.com>
Fri, 19 Aug 2011 12:14:54 +0000 (14:14 +0200)
This is just a style check. Option names should be consistent. Since all
of them go through the “build-bash-completion” script, this seemed to be
a good place.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

autotools/build-bash-completion

index 8af38af..bfea351 100755 (executable)
@@ -28,6 +28,7 @@
 
 import os
 import re
+import itertools
 from cStringIO import StringIO
 
 from ganeti import constants
@@ -39,6 +40,10 @@ from ganeti import build
 # making an exception here because this script is only used at build time.
 from ganeti import _autoconf
 
+#: Regular expression describing desired format of option names. Long names can
+#: contain lowercase characters, numbers and dashes only.
+_OPT_NAME_RE = re.compile(r"^-[a-zA-Z0-9]|--[a-z][-a-z0-9]+$")
+
 
 def WritePreamble(sw):
   """Writes the script preamble.
@@ -244,6 +249,11 @@ class CompletionWriter:
       # pylint. pylint: disable-msg=W0212
       opt.all_names = sorted(opt._short_opts + opt._long_opts)
 
+      invalid = list(itertools.ifilterfalse(_OPT_NAME_RE.match, opt.all_names))
+      if invalid:
+        raise Exception("Option names don't match regular expression '%s': %s" %
+                        (_OPT_NAME_RE.pattern, utils.CommaJoin(invalid)))
+
   def _FindFirstArgument(self, sw):
     ignore = []
     skip_one = []