diff options
author | Mike Frysinger <vapier@google.com> | 2019-12-02 16:49:44 -0500 |
---|---|---|
committer | David Pursehouse <dpursehouse@collab.net> | 2019-12-05 05:00:21 +0000 |
commit | 7c321f1bf6c19efdeae1042acfff5933ab4b376f (patch) | |
tree | 4deadb4e6d60fd6e8d990f309b2e0c83719f2416 /main.py | |
parent | 7ac12a9b2296028a2e9fe5eb8a0dcc07c81a630a (diff) | |
download | git-repo-7c321f1bf6c19efdeae1042acfff5933ab4b376f.tar.gz |
repo: include subcommands in --help output
Also point people to `repo help` so it's easier to navigate the tool.
Bug: https://crbug.com/gerrit/12022
Change-Id: Ib3be331a2cef32caa193640bf8d54bd1443fce60
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/247292
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Diffstat (limited to 'main.py')
-rwxr-xr-x | main.py | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -27,6 +27,7 @@ import netrc | |||
27 | import optparse | 27 | import optparse |
28 | import os | 28 | import os |
29 | import sys | 29 | import sys |
30 | import textwrap | ||
30 | import time | 31 | import time |
31 | 32 | ||
32 | from pyversion import is_python3 | 33 | from pyversion import is_python3 |
@@ -71,8 +72,10 @@ if not is_python3(): | |||
71 | input = raw_input | 72 | input = raw_input |
72 | 73 | ||
73 | global_options = optparse.OptionParser( | 74 | global_options = optparse.OptionParser( |
74 | usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]" | 75 | usage='repo [-p|--paginate|--no-pager] COMMAND [ARGS]', |
75 | ) | 76 | add_help_option=False) |
77 | global_options.add_option('-h', '--help', action='store_true', | ||
78 | help='show this help message and exit') | ||
76 | global_options.add_option('-p', '--paginate', | 79 | global_options.add_option('-p', '--paginate', |
77 | dest='pager', action='store_true', | 80 | dest='pager', action='store_true', |
78 | help='display command output in the pager') | 81 | help='display command output in the pager') |
@@ -123,6 +126,14 @@ class _Repo(object): | |||
123 | argv = [] | 126 | argv = [] |
124 | gopts, _gargs = global_options.parse_args(glob) | 127 | gopts, _gargs = global_options.parse_args(glob) |
125 | 128 | ||
129 | if gopts.help: | ||
130 | global_options.print_help() | ||
131 | commands = ' '.join(sorted(self.commands)) | ||
132 | wrapped_commands = textwrap.wrap(commands, width=77) | ||
133 | print('\nAvailable commands:\n %s' % ('\n '.join(wrapped_commands),)) | ||
134 | print('\nRun `repo help <command>` for command-specific details.') | ||
135 | global_options.exit() | ||
136 | |||
126 | return (name, gopts, argv) | 137 | return (name, gopts, argv) |
127 | 138 | ||
128 | def _Run(self, name, gopts, argv): | 139 | def _Run(self, name, gopts, argv): |