OLD | NEW |
1 # Copyright (c) 2010 Google Inc. All rights reserved. | 1 # Copyright (c) 2010 Google Inc. All rights reserved. |
2 # Copyright (c) 2009 Apple Inc. All rights reserved. | 2 # Copyright (c) 2009 Apple Inc. All rights reserved. |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 PrettyDiff(), | 89 PrettyDiff(), |
90 PrintBaselines(), | 90 PrintBaselines(), |
91 PrintExpectations(), | 91 PrintExpectations(), |
92 Rebaseline(), | 92 Rebaseline(), |
93 RebaselineCL(), | 93 RebaselineCL(), |
94 RebaselineExpectations(), | 94 RebaselineExpectations(), |
95 RebaselineJson(), | 95 RebaselineJson(), |
96 RebaselineServer(), | 96 RebaselineServer(), |
97 RebaselineTest(), | 97 RebaselineTest(), |
98 ] | 98 ] |
99 self.help_command = HelpCommand() | 99 self.help_command = HelpCommand(tool=self) |
100 self.commands.append(self.help_command) | 100 self.commands.append(self.help_command) |
101 | 101 |
102 def main(self, argv=None): | 102 def main(self, argv=None): |
103 argv = argv or sys.argv | 103 argv = argv or sys.argv |
104 (command_name, args) = self._split_command_name_from_args(argv[1:]) | 104 (command_name, args) = self._split_command_name_from_args(argv[1:]) |
105 | 105 |
106 option_parser = self._create_option_parser() | 106 option_parser = self._create_option_parser() |
107 self._add_global_options(option_parser) | 107 self._add_global_options(option_parser) |
108 | 108 |
109 command = self.command_by_name(command_name) or self.help_command | 109 command = self.command_by_name(command_name) or self.help_command |
(...skipping 25 matching lines...) Expand all Loading... |
135 command_index += 1 | 135 command_index += 1 |
136 else: | 136 else: |
137 return (None, args[:]) | 137 return (None, args[:]) |
138 | 138 |
139 command = args[command_index] | 139 command = args[command_index] |
140 return (command, args[:command_index] + args[command_index + 1:]) | 140 return (command, args[:command_index] + args[command_index + 1:]) |
141 | 141 |
142 def _create_option_parser(self): | 142 def _create_option_parser(self): |
143 usage = "Usage: %prog [options] COMMAND [ARGS]" | 143 usage = "Usage: %prog [options] COMMAND [ARGS]" |
144 name = optparse.OptionParser().get_prog_name() | 144 name = optparse.OptionParser().get_prog_name() |
145 return HelpPrintingOptionParser(epilog_method=self.help_command._help_ep
ilog, prog=name, usage=usage) | 145 return HelpPrintingOptionParser(epilog_method=self.help_command.help_epi
log, prog=name, usage=usage) |
146 | 146 |
147 def _add_global_options(self, option_parser): | 147 def _add_global_options(self, option_parser): |
148 global_options = self.global_options or [] | 148 global_options = self.global_options or [] |
149 for option in global_options: | 149 for option in global_options: |
150 option_parser.add_option(option) | 150 option_parser.add_option(option) |
151 | 151 |
152 # FIXME: This may be unnecessary since we pass global options to all command
s during execute() as well. | 152 # FIXME: This may be unnecessary since we pass global options to all command
s during execute() as well. |
153 def _handle_global_options(self, options): | 153 def _handle_global_options(self, options): |
154 self.initialize_scm(options.patch_directories) | 154 self.initialize_scm(options.patch_directories) |
155 | 155 |
(...skipping 12 matching lines...) Expand all Loading... |
168 return False | 168 return False |
169 if command.requires_local_commits: | 169 if command.requires_local_commits: |
170 return self.scm().supports_local_commits() | 170 return self.scm().supports_local_commits() |
171 return True | 171 return True |
172 | 172 |
173 def command_by_name(self, command_name): | 173 def command_by_name(self, command_name): |
174 for command in self.commands: | 174 for command in self.commands: |
175 if command_name == command.name: | 175 if command_name == command.name: |
176 return command | 176 return command |
177 return None | 177 return None |
OLD | NEW |