From 0b304c06ffdf3072fc498683be3e237f9b611a02 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 2 Dec 2019 16:49:13 -0500 Subject: help: unify command display No functional changes, just unifying duplicate code paths. Change-Id: I6afa797ca1e1eb90abdc0236325003ae070cbfb3 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/247293 Reviewed-by: David Pursehouse Tested-by: Mike Frysinger --- subcmds/help.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'subcmds/help.py') diff --git a/subcmds/help.py b/subcmds/help.py index 16f1f7f9..78930502 100644 --- a/subcmds/help.py +++ b/subcmds/help.py @@ -33,11 +33,8 @@ class Help(PagedCommand, MirrorSafeCommand): Displays detailed usage information about a command. """ - def _PrintAllCommands(self): - print('usage: repo COMMAND [ARGS]') - print('The complete list of recognized repo commands are:') - commandNames = list(sorted(self.commands)) - + def _PrintCommands(self, commandNames): + """Helper to display |commandNames| summaries.""" maxlen = 0 for name in commandNames: maxlen = max(maxlen, len(name)) @@ -50,6 +47,12 @@ Displays detailed usage information about a command. except AttributeError: summary = '' print(fmt % (name, summary)) + + def _PrintAllCommands(self): + print('usage: repo COMMAND [ARGS]') + print('The complete list of recognized repo commands are:') + commandNames = list(sorted(self.commands)) + self._PrintCommands(commandNames) print("See 'repo help ' for more information on a " 'specific command.') @@ -71,19 +74,8 @@ Displays detailed usage information about a command. commandNames = list(sorted([name for name, command in self.commands.items() if command.common and gitc_supported(command)])) + self._PrintCommands(commandNames) - maxlen = 0 - for name in commandNames: - maxlen = max(maxlen, len(name)) - fmt = ' %%-%ds %%s' % maxlen - - for name in commandNames: - command = self.commands[name] - try: - summary = command.helpSummary.strip() - except AttributeError: - summary = '' - print(fmt % (name, summary)) print( "See 'repo help ' for more information on a specific command.\n" "See 'repo help --all' for a complete list of recognized commands.") -- cgit v1.2.3-54-g00ecf