Bug 1255467 - Ability for a mach command to dispatch to another's subcommand, r=gps
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Thu, 10 Mar 2016 11:45:39 -0500
changeset 339549 2f5f092a64add23c4bb911179a21352046848406
parent 339548 844d73172246061eab0a612454b4be5aefbcb0df
child 339550 28bca8e29596cfa1c24b864925cb5cb5e20e35ab
push id12762
push userbmo:rail@mozilla.com
push dateFri, 11 Mar 2016 19:47:45 +0000
reviewersgps
bugs1255467
milestone48.0a1
Bug 1255467 - Ability for a mach command to dispatch to another's subcommand, r=gps MozReview-Commit-ID: CN8kJU0NrL0
python/mach/mach/registrar.py
--- a/python/mach/mach/registrar.py
+++ b/python/mach/mach/registrar.py
@@ -94,32 +94,33 @@ class MachRegistrar(object):
 
         if context:
             postrun = getattr(context, 'post_dispatch_handler', None)
             if postrun:
                 postrun(context, handler, args=kwargs)
 
         return result
 
-    def dispatch(self, name, context=None, argv=None, **kwargs):
+    def dispatch(self, name, context=None, argv=None, subcommand=None, **kwargs):
         """Dispatch/run a command.
 
         Commands can use this to call other commands.
         """
-        # TODO handler.subcommand_handlers are ignored
         handler = self.command_handlers[name]
 
+        if subcommand:
+            handler = handler.subcommand_handlers[subcommand]
+
         if handler.parser:
             parser = handler.parser
 
             # save and restore existing defaults so **kwargs don't persist across
             # subsequent invocations of Registrar.dispatch()
             old_defaults = parser._defaults.copy()
             parser.set_defaults(**kwargs)
             kwargs, _ = parser.parse_known_args(argv or [])
             kwargs = vars(kwargs)
             parser._defaults = old_defaults
 
         return self._run_command_handler(handler, context=context, **kwargs)
 
 
-
 Registrar = MachRegistrar()