Bug 908868 - Add code to the 'mach help' command to show disabled commands. r=gps
authorSebastiaan de Haan <me@sebastiaandehaan.nl>
Fri, 11 Oct 2013 13:41:25 -0400
changeset 164345 6088d4495e46de48b591e6a4c09c42b55bc3525d
parent 164344 1590742133fa6eaf5ca8007ab45431177be17a97
child 164346 c3d14caa839ac76b0d1f8b0d6687e28b486f7617
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs908868
milestone27.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 908868 - Add code to the 'mach help' command to show disabled commands. r=gps
build/mach_bootstrap.py
python/mach/mach/dispatcher.py
--- a/build/mach_bootstrap.py
+++ b/build/mach_bootstrap.py
@@ -103,16 +103,21 @@ CATEGORIES = {
         'short': 'Low-level Build System Interaction',
         'long': 'Interact with specific parts of the build system.',
         'priority': 20,
     },
     'misc': {
         'short': 'Potpourri',
         'long': 'Potent potables and assorted snacks.',
         'priority': 10,
+    },
+    'disabled': {
+        'short': 'Disabled',
+        'long': 'These commands are unavailable for your current context, run "mach <command>" to see why.',
+        'priority': 0,
     }
 }
 
 
 def bootstrap(topsrcdir, mozilla_dir=None):
     if mozilla_dir is None:
         mozilla_dir = topsrcdir
 
--- a/python/mach/mach/dispatcher.py
+++ b/python/mach/mach/dispatcher.py
@@ -140,16 +140,17 @@ class CommandAction(argparse.Action):
             raise UnrecognizedArgumentError(command, extra)
 
     def _handle_main_help(self, parser):
         # Since we don't need full sub-parser support for the main help output,
         # we create groups in the ArgumentParser and populate each group with
         # arguments corresponding to command names. This has the side-effect
         # that argparse renders it nicely.
         r = self._mach_registrar
+        disabled_commands = []
 
         cats = [(k, v[2]) for k, v in r.categories.items()]
         sorted_cats = sorted(cats, key=itemgetter(1), reverse=True)
         for category, priority in sorted_cats:
             group = None
 
             for command in sorted(r.commands_by_category[category]):
                 handler = r.command_handlers[command]
@@ -164,26 +165,36 @@ class CommandAction(argparse.Action):
                         instance = handler.cls()
 
                     is_filtered = False
                     for c in handler.conditions:
                         if not c(instance):
                             is_filtered = True
                             break
                     if is_filtered:
+                        description = handler.description
+                        disabled_command = {'command': command, 'description': description}
+                        disabled_commands.append(disabled_command)
                         continue
 
                 if group is None:
                     title, description, _priority = r.categories[category]
                     group = parser.add_argument_group(title, description)
 
                 description = handler.description
                 group.add_argument(command, help=description,
                     action='store_true')
 
+        if disabled_commands:
+            title, description, _priority = r.categories['disabled']
+            group = parser.add_argument_group(title, description)
+            for c in disabled_commands:
+                group.add_argument(c['command'], help=c['description'],
+                    action='store_true')
+
         parser.print_help()
 
     def _handle_subcommand_help(self, parser, command):
         handler = self._mach_registrar.command_handlers.get(command)
 
         if not handler:
             raise UnknownCommandError(command, 'query')