]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Teach the optparse CLI about the parameter aliases it had forgotten in #311 389/head
authorAarni Koskela <akx@iki.fi>
Sun, 17 Apr 2016 15:20:10 +0000 (18:20 +0300)
committerAarni Koskela <akx@iki.fi>
Tue, 19 Apr 2016 18:29:11 +0000 (21:29 +0300)
Vaguely refs #390

babel/messages/frontend.py
tests/messages/test_frontend.py

index ee1e1855e7cb64a562fd186b13fd910904ca7f56..d190a2c07176c6aac1dca9c4c1c11f9be66ff6c4 100644 (file)
@@ -98,6 +98,12 @@ class Command(_Command):
     # declared in the base class.)
     boolean_options = ()
 
+    #: Option aliases, to retain standalone command compatibility.
+    #: Distutils does not support option aliases, but optparse does.
+    #: This maps the distutils argument name to an iterable of aliases
+    #: that are usable with optparse.
+    option_aliases = {}
+
     #: Log object. To allow replacement in the script command line runner.
     log = distutils_log
 
@@ -311,6 +317,12 @@ class extract_messages(Command):
     ]
     as_args = 'input-paths'
     multiple_value_options = ('add-comments', 'keywords')
+    option_aliases = {
+        'keywords': ('--keyword',),
+        'mapping-file': ('--mapping',),
+        'output-file': ('--output',),
+        'strip-comments': ('--strip-comment-tags',),
+    }
 
     def initialize_options(self):
         self.charset = 'utf-8'
@@ -870,6 +882,7 @@ class CommandLineInterface(object):
             strs = ["--%s" % name]
             if short:
                 strs.append("-%s" % short)
+            strs.extend(cmdclass.option_aliases.get(name, ()))
             if name == as_args:
                 parser.usage += "<%s>" % name
             elif name in cmdclass.boolean_options:
index 26f6cce1929c08484e81611a54f1d7bdc95a6a26..7488bcc57f2666c6a7fead619fdfe377ff57edc8 100644 (file)
@@ -1267,8 +1267,12 @@ def configure_distutils_command(cmdline):
 
 
 @pytest.mark.parametrize("split", (False, True))
-def test_extract_keyword_args_384(split):
+@pytest.mark.parametrize("arg_name", ("-k", "--keyword", "--keywords"))
+def test_extract_keyword_args_384(split, arg_name):
     # This is a regression test for https://github.com/python-babel/babel/issues/384
+    # and it also tests that the rest of the forgotten aliases/shorthands implied by
+    # https://github.com/python-babel/babel/issues/390 are re-remembered (or rather
+    # that the mechanism for remembering them again works).
 
     kwarg_specs = [
         "gettext_noop",
@@ -1282,9 +1286,9 @@ def test_extract_keyword_args_384(split):
     ]
 
     if split:  # Generate a command line with multiple -ks
-        kwarg_text = " ".join("-k %s" % kwarg_spec for kwarg_spec in kwarg_specs)
+        kwarg_text = " ".join("%s %s" % (arg_name, kwarg_spec) for kwarg_spec in kwarg_specs)
     else:  # Generate a single space-separated -k
-        kwarg_text = "-k \"%s\"" % " ".join(kwarg_specs)
+        kwarg_text = "%s \"%s\"" % (arg_name, " ".join(kwarg_specs))
 
     # (Both of those invocation styles should be equivalent, so there is no parametrization from here on out)