Changeset 51208 in webkit


Ignore:
Timestamp:
Nov 19, 2009 3:21:03 PM (14 years ago)
Author:
eric@webkit.org
Message:

2009-11-19 Eric Seidel <eric@webkit.org>

Reviewed by Adam Barth.

Re-factor help printing to use modern python idioms
https://bugs.webkit.org/show_bug.cgi?id=31685

  • Scripts/bugzilla-tool:
Location:
trunk/WebKitTools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r51203 r51208  
     12009-11-19  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Re-factor help printing to use modern python idioms
     6        https://bugs.webkit.org/show_bug.cgi?id=31685
     7
     8        * Scripts/bugzilla-tool:
     9
    1102009-11-19  Eric Seidel  <eric@webkit.org>
    211
  • trunk/WebKitTools/Scripts/bugzilla-tool

    r51203 r51208  
    9090        self.option_parser = HelpPrintingOptionParser(usage=SUPPRESS_USAGE, add_help_option=False, option_list=self.options)
    9191        self.requires_local_commits = requires_local_commits
    92    
     92
    9393    def name_with_arguments(self, command_name):
    9494        usage_string = command_name
     
    904904        return "Usage: %prog [options] command [command-options] [command-arguments]"
    905905
    906     def commands_usage(self):
    907         commands_text = "Commands:\n"
    908         longest_name_length = 0
    909         command_rows = []
    910         scm_supports_local_commits = self.scm().supports_local_commits()
    911         for command in self.commands:
    912             command_object = command["object"]
    913             if command_object.requires_local_commits and not scm_supports_local_commits:
    914                 continue
    915             command_name_and_args = command_object.name_with_arguments(command["name"])
    916             command_rows.append({ "name-and-args": command_name_and_args, "object": command_object })
    917             longest_name_length = max([longest_name_length, len(command_name_and_args)])
    918        
     906    # FIXME: This can all be simplified once Command objects know their own names.
     907    @staticmethod
     908    def _name_and_arguments(command):
     909        return command['object'].name_with_arguments(command["name"])
     910
     911    def _command_help_formatter(self):
    919912        # Use our own help formatter so as to indent enough.
    920913        formatter = IndentedHelpFormatter()
    921914        formatter.indent()
    922915        formatter.indent()
    923        
    924         for row in command_rows:
    925             command_object = row["object"]
    926             commands_text += "  " + row["name-and-args"].ljust(longest_name_length + 3) + command_object.help_text + "\n"
    927             commands_text += command_object.option_parser.format_option_help(formatter)
    928         return commands_text
     916        return formatter
     917
     918    @classmethod
     919    def _help_for_command(cls, command, formatter, longest_name_length):
     920        help_text = "  " + cls._name_and_arguments(command).ljust(longest_name_length + 3) + command['object'].help_text + "\n"
     921        help_text += command['object'].option_parser.format_option_help(formatter)
     922        return help_text
     923
     924    def commands_usage(self):
     925        if not self.scm().supports_local_commits():
     926            command_filter = lambda command: not command["object"].requires_local_commits
     927        else:
     928            command_filter = None
     929
     930        # Only show commands which are relevant to this checkout.  This might be confusing to some users?
     931        relevant_commands = filter(command_filter, self.commands)
     932        longest_name_length = max(map(lambda command: len(self._name_and_arguments(command)), relevant_commands))
     933        command_help_texts = map(lambda command: self._help_for_command(command, self._command_help_formatter(), longest_name_length), relevant_commands)
     934        return "Commands:\n" + "".join(command_help_texts)
    929935
    930936    def handle_global_args(self, args):
     
    968974        if not command_name:
    969975            self.global_option_parser.error("No command specified")
    970        
     976
    971977        command = self.command_by_name(command_name)
    972978        if not command:
Note: See TracChangeset for help on using the changeset viewer.