diff options
| author | Mike Frysinger <vapier@google.com> | 2019-12-02 16:49:13 -0500 |
|---|---|---|
| committer | Mike Frysinger <vapier@google.com> | 2019-12-03 02:31:05 +0000 |
| commit | 0b304c06ffdf3072fc498683be3e237f9b611a02 (patch) | |
| tree | 1fcdfa8c33c6ff60fda76f7bc908cf0faf7a2355 | |
| parent | 4997d1c83870c00ec7934ce55570e1d3fbade66f (diff) | |
| download | git-repo-0b304c06ffdf3072fc498683be3e237f9b611a02.tar.gz | |
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 <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
| -rw-r--r-- | subcmds/help.py | 26 |
1 files changed, 9 insertions, 17 deletions
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): | |||
| 33 | Displays detailed usage information about a command. | 33 | Displays detailed usage information about a command. |
| 34 | """ | 34 | """ |
| 35 | 35 | ||
| 36 | def _PrintAllCommands(self): | 36 | def _PrintCommands(self, commandNames): |
| 37 | print('usage: repo COMMAND [ARGS]') | 37 | """Helper to display |commandNames| summaries.""" |
| 38 | print('The complete list of recognized repo commands are:') | ||
| 39 | commandNames = list(sorted(self.commands)) | ||
| 40 | |||
| 41 | maxlen = 0 | 38 | maxlen = 0 |
| 42 | for name in commandNames: | 39 | for name in commandNames: |
| 43 | maxlen = max(maxlen, len(name)) | 40 | maxlen = max(maxlen, len(name)) |
| @@ -50,6 +47,12 @@ Displays detailed usage information about a command. | |||
| 50 | except AttributeError: | 47 | except AttributeError: |
| 51 | summary = '' | 48 | summary = '' |
| 52 | print(fmt % (name, summary)) | 49 | print(fmt % (name, summary)) |
| 50 | |||
| 51 | def _PrintAllCommands(self): | ||
| 52 | print('usage: repo COMMAND [ARGS]') | ||
| 53 | print('The complete list of recognized repo commands are:') | ||
| 54 | commandNames = list(sorted(self.commands)) | ||
| 55 | self._PrintCommands(commandNames) | ||
| 53 | print("See 'repo help <command>' for more information on a " | 56 | print("See 'repo help <command>' for more information on a " |
| 54 | 'specific command.') | 57 | 'specific command.') |
| 55 | 58 | ||
| @@ -71,19 +74,8 @@ Displays detailed usage information about a command. | |||
| 71 | commandNames = list(sorted([name | 74 | commandNames = list(sorted([name |
| 72 | for name, command in self.commands.items() | 75 | for name, command in self.commands.items() |
| 73 | if command.common and gitc_supported(command)])) | 76 | if command.common and gitc_supported(command)])) |
| 77 | self._PrintCommands(commandNames) | ||
| 74 | 78 | ||
| 75 | maxlen = 0 | ||
| 76 | for name in commandNames: | ||
| 77 | maxlen = max(maxlen, len(name)) | ||
| 78 | fmt = ' %%-%ds %%s' % maxlen | ||
| 79 | |||
| 80 | for name in commandNames: | ||
| 81 | command = self.commands[name] | ||
| 82 | try: | ||
| 83 | summary = command.helpSummary.strip() | ||
| 84 | except AttributeError: | ||
| 85 | summary = '' | ||
| 86 | print(fmt % (name, summary)) | ||
| 87 | print( | 79 | print( |
| 88 | "See 'repo help <command>' for more information on a specific command.\n" | 80 | "See 'repo help <command>' for more information on a specific command.\n" |
| 89 | "See 'repo help --all' for a complete list of recognized commands.") | 81 | "See 'repo help --all' for a complete list of recognized commands.") |
