From 7c321f1bf6c19efdeae1042acfff5933ab4b376f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 2 Dec 2019 16:49:44 -0500 Subject: [PATCH] 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 Reviewed-by: David Pursehouse --- main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 6e74d5a4..16db144f 100755 --- a/main.py +++ b/main.py @@ -27,6 +27,7 @@ import netrc import optparse import os import sys +import textwrap import time from pyversion import is_python3 @@ -71,8 +72,10 @@ if not is_python3(): input = raw_input global_options = optparse.OptionParser( - usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]" - ) + usage='repo [-p|--paginate|--no-pager] COMMAND [ARGS]', + add_help_option=False) +global_options.add_option('-h', '--help', action='store_true', + help='show this help message and exit') global_options.add_option('-p', '--paginate', dest='pager', action='store_true', help='display command output in the pager') @@ -123,6 +126,14 @@ class _Repo(object): argv = [] gopts, _gargs = global_options.parse_args(glob) + if gopts.help: + global_options.print_help() + commands = ' '.join(sorted(self.commands)) + wrapped_commands = textwrap.wrap(commands, width=77) + print('\nAvailable commands:\n %s' % ('\n '.join(wrapped_commands),)) + print('\nRun `repo help ` for command-specific details.') + global_options.exit() + return (name, gopts, argv) def _Run(self, name, gopts, argv):