diff options
Diffstat (limited to 'main.py')
| -rwxr-xr-x | main.py | 48 |
1 files changed, 24 insertions, 24 deletions
| @@ -130,32 +130,21 @@ class _Repo(object): | |||
| 130 | 130 | ||
| 131 | def _ParseArgs(self, argv): | 131 | def _ParseArgs(self, argv): |
| 132 | """Parse the main `repo` command line options.""" | 132 | """Parse the main `repo` command line options.""" |
| 133 | name = None | 133 | for i, arg in enumerate(argv): |
| 134 | glob = [] | 134 | if not arg.startswith('-'): |
| 135 | 135 | name = arg | |
| 136 | for i in range(len(argv)): | 136 | glob = argv[:i] |
| 137 | if not argv[i].startswith('-'): | ||
| 138 | name = argv[i] | ||
| 139 | if i > 0: | ||
| 140 | glob = argv[:i] | ||
| 141 | argv = argv[i + 1:] | 137 | argv = argv[i + 1:] |
| 142 | break | 138 | break |
| 143 | if not name: | 139 | else: |
| 140 | name = None | ||
| 144 | glob = argv | 141 | glob = argv |
| 145 | name = 'help' | ||
| 146 | argv = [] | 142 | argv = [] |
| 147 | gopts, _gargs = global_options.parse_args(glob) | 143 | gopts, _gargs = global_options.parse_args(glob) |
| 148 | 144 | ||
| 149 | name, alias_args = self._ExpandAlias(name) | 145 | if name: |
| 150 | argv = alias_args + argv | 146 | name, alias_args = self._ExpandAlias(name) |
| 151 | 147 | argv = alias_args + argv | |
| 152 | if gopts.help: | ||
| 153 | global_options.print_help() | ||
| 154 | commands = ' '.join(sorted(self.commands)) | ||
| 155 | wrapped_commands = textwrap.wrap(commands, width=77) | ||
| 156 | print('\nAvailable commands:\n %s' % ('\n '.join(wrapped_commands),)) | ||
| 157 | print('\nRun `repo help <command>` for command-specific details.') | ||
| 158 | global_options.exit() | ||
| 159 | 148 | ||
| 160 | return (name, gopts, argv) | 149 | return (name, gopts, argv) |
| 161 | 150 | ||
| @@ -186,12 +175,23 @@ class _Repo(object): | |||
| 186 | 175 | ||
| 187 | if gopts.trace: | 176 | if gopts.trace: |
| 188 | SetTrace() | 177 | SetTrace() |
| 189 | if gopts.show_version: | 178 | |
| 190 | if name == 'help': | 179 | # Handle options that terminate quickly first. |
| 191 | name = 'version' | 180 | if gopts.help: |
| 192 | else: | 181 | global_options.print_help() |
| 182 | commands = ' '.join(sorted(self.commands)) | ||
| 183 | wrapped_commands = textwrap.wrap(commands, width=77) | ||
| 184 | print('\nAvailable commands:\n %s' % ('\n '.join(wrapped_commands),)) | ||
| 185 | print('\nRun `repo help <command>` for command-specific details.') | ||
| 186 | return 0 | ||
| 187 | elif gopts.show_version: | ||
| 188 | if name and name != 'help': | ||
| 193 | print('fatal: invalid usage of --version', file=sys.stderr) | 189 | print('fatal: invalid usage of --version', file=sys.stderr) |
| 194 | return 1 | 190 | return 1 |
| 191 | name = 'version' | ||
| 192 | elif not name: | ||
| 193 | # No subcommand specified, so show the help/subcommand. | ||
| 194 | name = 'help' | ||
| 195 | 195 | ||
| 196 | SetDefaultColoring(gopts.color) | 196 | SetDefaultColoring(gopts.color) |
| 197 | 197 | ||
