help: add a --help-all option to show all commands at once

This is useful when you want to scan all the possibilities of repo
at once.  Like when you're searching for different option names.

Change-Id: I225dfb94d2be78229905b744ecf57eb2829bb52d
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/232894
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2019-07-31 18:17:44 -04:00
parent d9e5cf0ee7
commit 898f4e6217

View File

@ -88,7 +88,7 @@ Displays detailed usage information about a command.
"See 'repo help <command>' for more information on a specific command.\n" "See 'repo help <command>' for more information on a specific command.\n"
"See 'repo help --all' for a complete list of recognized commands.") "See 'repo help --all' for a complete list of recognized commands.")
def _PrintCommandHelp(self, cmd): def _PrintCommandHelp(self, cmd, header_prefix=''):
class _Out(Coloring): class _Out(Coloring):
def __init__(self, gc): def __init__(self, gc):
Coloring.__init__(self, gc, 'help') Coloring.__init__(self, gc, 'help')
@ -106,7 +106,7 @@ Displays detailed usage information about a command.
self.nl() self.nl()
self.heading('%s', heading) self.heading('%s%s', header_prefix, heading)
self.nl() self.nl()
self.nl() self.nl()
@ -124,7 +124,7 @@ Displays detailed usage information about a command.
m = asciidoc_hdr.match(para) m = asciidoc_hdr.match(para)
if m: if m:
self.heading(m.group(1)) self.heading('%s%s', header_prefix, m.group(1))
self.nl() self.nl()
self.nl() self.nl()
continue continue
@ -138,14 +138,25 @@ Displays detailed usage information about a command.
cmd.OptionParser.print_help() cmd.OptionParser.print_help()
out._PrintSection('Description', 'helpDescription') out._PrintSection('Description', 'helpDescription')
def _PrintAllCommandHelp(self):
for name in sorted(self.commands):
cmd = self.commands[name]
cmd.manifest = self.manifest
self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,))
def _Options(self, p): def _Options(self, p):
p.add_option('-a', '--all', p.add_option('-a', '--all',
dest='show_all', action='store_true', dest='show_all', action='store_true',
help='show the complete list of commands') help='show the complete list of commands')
p.add_option('--help-all',
dest='show_all_help', action='store_true',
help='show the --help of all commands')
def Execute(self, opt, args): def Execute(self, opt, args):
if len(args) == 0: if len(args) == 0:
if opt.show_all: if opt.show_all_help:
self._PrintAllCommandHelp()
elif opt.show_all:
self._PrintAllCommands() self._PrintAllCommands()
else: else:
self._PrintCommonCommands() self._PrintCommonCommands()