Bug 1255467 - Ability for a mach command to dispatch to another's subcommand, r?gps draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Thu, 10 Mar 2016 11:45:39 -0500
changeset 339175 8d6f683b6ee193537c76aede509bcf5b50a39b67
parent 339110 dd1abe874252e507b825a0a4e1063b0e13578288
child 515920 c790c0ebf630a600360350bf182bf461cf4805ab
push id12650
push userahalberstadt@mozilla.com
push dateThu, 10 Mar 2016 16:59:39 +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()