| OLD | NEW |
| 1 # Copyright (c) 2016 Google Inc. All rights reserved. | 1 # Copyright (c) 2016 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 optparse.make_option( | 41 optparse.make_option( |
| 42 "-a", | 42 "-a", |
| 43 "--all-commands", | 43 "--all-commands", |
| 44 action="store_true", | 44 action="store_true", |
| 45 dest="show_all_commands", | 45 dest="show_all_commands", |
| 46 help="Print all available commands"), | 46 help="Print all available commands"), |
| 47 ] | 47 ] |
| 48 super(HelpCommand, self).__init__(options) | 48 super(HelpCommand, self).__init__(options) |
| 49 # A hack used to pass --all-commands to _help_epilog even though it's ca
lled by the OptionParser. | 49 # A hack used to pass --all-commands to _help_epilog even though it's ca
lled by the OptionParser. |
| 50 self.show_all_commands = False | 50 self.show_all_commands = False |
| 51 self._tool = None |
| 51 | 52 |
| 52 def _help_epilog(self): | 53 def _help_epilog(self): |
| 53 # Only show commands which are relevant to this checkout's SCM system.
Might this be confusing to some users? | 54 # Only show commands which are relevant to this checkout's SCM system.
Might this be confusing to some users? |
| 54 if self.show_all_commands: | 55 if self.show_all_commands: |
| 55 epilog = "All %prog commands:\n" | 56 epilog = "All %prog commands:\n" |
| 56 relevant_commands = self._tool.commands[:] | 57 relevant_commands = self._tool.commands[:] |
| 57 else: | 58 else: |
| 58 epilog = "Common %prog commands:\n" | 59 epilog = "Common %prog commands:\n" |
| 59 relevant_commands = filter(self._tool.should_show_in_main_help, self
._tool.commands) | 60 relevant_commands = filter(self._tool.should_show_in_main_help, self
._tool.commands) |
| 60 longest_name_length = max(len(command.name) for command in relevant_comm
ands) | 61 longest_name_length = max(len(command.name) for command in relevant_comm
ands) |
| 61 relevant_commands.sort(lambda a, b: cmp(a.name, b.name)) | 62 relevant_commands.sort(lambda a, b: cmp(a.name, b.name)) |
| 62 command_help_texts = [" %s %s\n" % (command.name.ljust(longest_name_
length), command.help_text) | 63 command_help_texts = [" %s %s\n" % (command.name.ljust(longest_name_
length), command.help_text) |
| 63 for command in relevant_commands] | 64 for command in relevant_commands] |
| 64 epilog += "%s\n" % "".join(command_help_texts) | 65 epilog += "%s\n" % "".join(command_help_texts) |
| 65 epilog += "See '%prog help --all-commands' to list all commands.\n" | 66 epilog += "See '%prog help --all-commands' to list all commands.\n" |
| 66 epilog += "See '%prog help COMMAND' for more information on a specific c
ommand.\n" | 67 epilog += "See '%prog help COMMAND' for more information on a specific c
ommand.\n" |
| 67 return epilog.replace("%prog", self._tool.name()) # Use of %prog here m
imics OptionParser.expand_prog_name(). | 68 return epilog.replace("%prog", self._tool.name()) # Use of %prog here m
imics OptionParser.expand_prog_name(). |
| 68 | 69 |
| 69 # FIXME: This is a hack so that we don't show --all-commands as a global opt
ion: | 70 # FIXME: This is a hack so that we don't show --all-commands as a global opt
ion: |
| 70 def _remove_help_options(self): | 71 def _remove_help_options(self): |
| 71 for option in self.options: | 72 for option in self.options: |
| 72 self.option_parser.remove_option(option.get_opt_string()) | 73 self.option_parser.remove_option(option.get_opt_string()) |
| 73 | 74 |
| 74 def execute(self, options, args, tool): | 75 def execute(self, options, args, tool): |
| 76 self._tool = tool |
| 75 if args: | 77 if args: |
| 76 command = self._tool.command_by_name(args[0]) | 78 command = self._tool.command_by_name(args[0]) |
| 77 if command: | 79 if command: |
| 78 print command.standalone_help() | 80 print command.standalone_help() |
| 79 return 0 | 81 return 0 |
| 80 | 82 |
| 81 self.show_all_commands = options.show_all_commands | 83 self.show_all_commands = options.show_all_commands |
| 82 self._remove_help_options() | 84 self._remove_help_options() |
| 83 self.option_parser.print_help() | 85 self.option_parser.print_help() |
| 84 return 0 | 86 return 0 |
| OLD | NEW |