diff options
Diffstat (limited to 'main.py')
-rwxr-xr-x | main.py | 30 |
1 files changed, 23 insertions, 7 deletions
@@ -95,6 +95,8 @@ global_options = optparse.OptionParser( | |||
95 | add_help_option=False) | 95 | add_help_option=False) |
96 | global_options.add_option('-h', '--help', action='store_true', | 96 | global_options.add_option('-h', '--help', action='store_true', |
97 | help='show this help message and exit') | 97 | help='show this help message and exit') |
98 | global_options.add_option('--help-all', action='store_true', | ||
99 | help='show this help message with all subcommands and exit') | ||
98 | global_options.add_option('-p', '--paginate', | 100 | global_options.add_option('-p', '--paginate', |
99 | dest='pager', action='store_true', | 101 | dest='pager', action='store_true', |
100 | help='display command output in the pager') | 102 | help='display command output in the pager') |
@@ -128,6 +130,23 @@ class _Repo(object): | |||
128 | self.repodir = repodir | 130 | self.repodir = repodir |
129 | self.commands = all_commands | 131 | self.commands = all_commands |
130 | 132 | ||
133 | def _PrintHelp(self, short: bool = False, all_commands: bool = False): | ||
134 | """Show --help screen.""" | ||
135 | global_options.print_help() | ||
136 | print() | ||
137 | if short: | ||
138 | commands = ' '.join(sorted(self.commands)) | ||
139 | wrapped_commands = textwrap.wrap(commands, width=77) | ||
140 | print('Available commands:\n %s' % ('\n '.join(wrapped_commands),)) | ||
141 | print('\nRun `repo help <command>` for command-specific details.') | ||
142 | print('Bug reports:', Wrapper().BUG_URL) | ||
143 | else: | ||
144 | cmd = self.commands['help']() | ||
145 | if all_commands: | ||
146 | cmd.PrintAllCommandsBody() | ||
147 | else: | ||
148 | cmd.PrintCommonCommandsBody() | ||
149 | |||
131 | def _ParseArgs(self, argv): | 150 | def _ParseArgs(self, argv): |
132 | """Parse the main `repo` command line options.""" | 151 | """Parse the main `repo` command line options.""" |
133 | for i, arg in enumerate(argv): | 152 | for i, arg in enumerate(argv): |
@@ -177,19 +196,16 @@ class _Repo(object): | |||
177 | SetTrace() | 196 | SetTrace() |
178 | 197 | ||
179 | # Handle options that terminate quickly first. | 198 | # Handle options that terminate quickly first. |
180 | if gopts.help: | 199 | if gopts.help or gopts.help_all: |
181 | global_options.print_help() | 200 | self._PrintHelp(short=False, all_commands=gopts.help_all) |
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 | 201 | return 0 |
187 | elif gopts.show_version: | 202 | elif gopts.show_version: |
188 | # Always allow global --version regardless of subcommand validity. | 203 | # Always allow global --version regardless of subcommand validity. |
189 | name = 'version' | 204 | name = 'version' |
190 | elif not name: | 205 | elif not name: |
191 | # No subcommand specified, so show the help/subcommand. | 206 | # No subcommand specified, so show the help/subcommand. |
192 | name = 'help' | 207 | self._PrintHelp(short=True) |
208 | return 1 | ||
193 | 209 | ||
194 | SetDefaultColoring(gopts.color) | 210 | SetDefaultColoring(gopts.color) |
195 | 211 | ||