]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Make the command-line frontend easier to test
authorAarni Koskela <akx@iki.fi>
Mon, 11 Apr 2016 10:28:37 +0000 (13:28 +0300)
committerAarni Koskela <akx@iki.fi>
Tue, 12 Apr 2016 07:33:04 +0000 (10:33 +0300)
babel/messages/frontend.py

index 3cacec9d3e625339783e40c53919d6daeeb6c0f0..acf4a5fef52c0c7c2b1d6879d57a2cd269b0c9cf 100644 (file)
@@ -720,6 +720,8 @@ class CommandLineInterface(object):
         'update': update_catalog,
     }
 
+    log = None  # Replaced on instance level
+
     def run(self, argv=None):
         """Main entry point of the command-line interface.
 
@@ -768,7 +770,8 @@ class CommandLineInterface(object):
         if cmdname not in self.commands:
             self.parser.error('unknown command "%s"' % cmdname)
 
-        return self._dispatch(cmdname, args[1:])
+        cmdinst = self._configure_command(cmdname, args[1:])
+        return cmdinst.run()
 
     def _configure_logging(self, loglevel):
         self.log = logging.getLogger('babel')
@@ -794,14 +797,15 @@ class CommandLineInterface(object):
         for name, description in commands:
             print(format % (name, description))
 
-    def _dispatch(self, cmdname, argv):
+    def _configure_command(self, cmdname, argv):
         """
         :type cmdname: str
         :type argv: list[str]
         """
         cmdclass = self.command_classes[cmdname]
         cmdinst = cmdclass()
-        cmdinst.log = self.log  # Use our logger, not distutils'.
+        if self.log:
+            cmdinst.log = self.log  # Use our logger, not distutils'.
         assert isinstance(cmdinst, Command)
         cmdinst.initialize_options()
 
@@ -837,7 +841,7 @@ class CommandLineInterface(object):
         except DistutilsOptionError as err:
             parser.error(str(err))
 
-        cmdinst.run()
+        return cmdinst
 
 
 def main():