Bug 841445 - Make 'mach help <command>' call print_help directly [r=gps]
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 26 Mar 2013 11:15:08 -0700
changeset 136615 c9bf19d37fe084efd285fb985784a0d92a02f978
parent 136614 520cfa198f1d6ea2b668d4611342025151feffa6
child 136634 178a4a770bb1664d431eb0428f057bb48f0ad1ba
child 136696 2364a0a62c0274453481a974134290cb38d68ca5
child 138393 406766ad33f75a0dc09a8d143698913aae263188
push id2452
push userlsblakk@mozilla.com
push dateMon, 13 May 2013 16:59:38 +0000
treeherdermozilla-beta@d4b152d29d8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs841445
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 841445 - Make 'mach help <command>' call print_help directly [r=gps] DONTBUILD (not part of the build)
python/mach/mach/base.py
python/mach/mach/main.py
python/mach/mach/registrar.py
--- a/python/mach/mach/base.py
+++ b/python/mach/mach/base.py
@@ -28,16 +28,19 @@ class MethodHandler(object):
         # it instantiates classes.
         'pass_context',
 
         # The name of the method providing the command. In other words, this
         # is the str name of the attribute on the class type corresponding to
         # the name of the function.
         'method',
 
+        # The argparse subparser for this command's arguments.
+        'parser',
+
         # Arguments passed to add_parser() on the main mach subparser. This is
         # a 2-tuple of positional and named arguments, respectively.
         'parser_args',
 
         # Arguments added to this command's parser. This is a 2-tuple of
         # positional and named arguments, respectively.
         'arguments',
     )
--- a/python/mach/mach/main.py
+++ b/python/mach/mach/main.py
@@ -252,20 +252,19 @@ To see more help for a specific command,
 
         if args.command == 'help':
             if args.subcommand is None:
                 parser.usage = \
                     '%(prog)s [global arguments] command [command arguments]'
                 parser.print_help()
                 return 0
 
-            # ArgumentParser doesn't seem to have a public API to expose the
-            # subparsers. So, we just simulate the behavior that causes
-            # ArgumentParser to do the printing for us.
-            return self._run([args.subcommand, '--help'])
+            handler = Registrar.command_handlers[args.subcommand]
+            handler.parser.print_help()
+            return 0
 
         # Add JSON logging to a file if requested.
         if args.logfile:
             self.log_manager.add_json_handler(args.logfile)
 
         # Up the logging level if requested.
         log_level = logging.INFO
         if args.verbose:
--- a/python/mach/mach/registrar.py
+++ b/python/mach/mach/registrar.py
@@ -20,20 +20,21 @@ class MachRegistrar(object):
         self.command_handlers[name] = handler
 
     def register_settings_provider(self, cls):
         self.settings_providers.add(cls)
 
     def populate_argument_parser(self, parser):
         for command in sorted(self.command_handlers.keys()):
             handler = self.command_handlers[command]
-            p = parser.add_parser(*handler.parser_args[0],
+            handler.parser = parser.add_parser(*handler.parser_args[0],
                 **handler.parser_args[1])
 
             for arg in handler.arguments:
-                p.add_argument(*arg[0], **arg[1])
+                handler.parser.add_argument(*arg[0], **arg[1])
 
-            p.set_defaults(mach_class=handler.cls, mach_method=handler.method,
+            handler.parser.set_defaults(mach_class=handler.cls,
+                mach_method=handler.method,
                 mach_pass_context=handler.pass_context)
 
 
 Registrar = MachRegistrar()