diff options
| author | Mike Frysinger <vapier@google.com> | 2020-02-25 15:12:37 -0500 |
|---|---|---|
| committer | David Pursehouse <dpursehouse@collab.net> | 2020-03-17 00:08:52 +0000 |
| commit | d3639c53d56feaea81474ffd28395a124744dab7 (patch) | |
| tree | e48227c75bb55a08c342f0a2d8e6ced9cadad5a7 /subcmds | |
| parent | f725e548db17281037d794f18aab3320d2580865 (diff) | |
| download | git-repo-d3639c53d56feaea81474ffd28395a124744dab7.tar.gz | |
subcmds: centralize all_commands logic
The branch->branches alias is setup in the main module when that
really belongs in the existing all_commands setup.
For help, rather than monkey patching all_commands to the class,
switch it to use the state directly from the module. This makes
it a bit more obvious where it's coming from rather than this one
subcommand having a |commands| member added externally to it.
Change-Id: I0200def09bf4774cad8012af0f4ae60ea3089dc0
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/259153
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Diffstat (limited to 'subcmds')
| -rw-r--r-- | subcmds/__init__.py | 4 | ||||
| -rw-r--r-- | subcmds/help.py | 13 |
2 files changed, 9 insertions, 8 deletions
diff --git a/subcmds/__init__.py b/subcmds/__init__.py index 9cc94718..a49e7bd3 100644 --- a/subcmds/__init__.py +++ b/subcmds/__init__.py | |||
| @@ -46,5 +46,5 @@ for py in os.listdir(my_dir): | |||
| 46 | cmd.NAME = name | 46 | cmd.NAME = name |
| 47 | all_commands[name] = cmd | 47 | all_commands[name] = cmd |
| 48 | 48 | ||
| 49 | if 'help' in all_commands: | 49 | # Add 'branch' as an alias for 'branches'. |
| 50 | all_commands['help'].commands = all_commands | 50 | all_commands['branch'] = all_commands['branches'] |
diff --git a/subcmds/help.py b/subcmds/help.py index 36b3a7ae..5e24ed0b 100644 --- a/subcmds/help.py +++ b/subcmds/help.py | |||
| @@ -19,6 +19,7 @@ import re | |||
| 19 | import sys | 19 | import sys |
| 20 | from formatter import AbstractFormatter, DumbWriter | 20 | from formatter import AbstractFormatter, DumbWriter |
| 21 | 21 | ||
| 22 | from subcmds import all_commands | ||
| 22 | from color import Coloring | 23 | from color import Coloring |
| 23 | from command import PagedCommand, MirrorSafeCommand, GitcAvailableCommand, GitcClientCommand | 24 | from command import PagedCommand, MirrorSafeCommand, GitcAvailableCommand, GitcClientCommand |
| 24 | import gitc_utils | 25 | import gitc_utils |
| @@ -42,7 +43,7 @@ Displays detailed usage information about a command. | |||
| 42 | fmt = ' %%-%ds %%s' % maxlen | 43 | fmt = ' %%-%ds %%s' % maxlen |
| 43 | 44 | ||
| 44 | for name in commandNames: | 45 | for name in commandNames: |
| 45 | command = self.commands[name] | 46 | command = all_commands[name] |
| 46 | try: | 47 | try: |
| 47 | summary = command.helpSummary.strip() | 48 | summary = command.helpSummary.strip() |
| 48 | except AttributeError: | 49 | except AttributeError: |
| @@ -52,7 +53,7 @@ Displays detailed usage information about a command. | |||
| 52 | def _PrintAllCommands(self): | 53 | def _PrintAllCommands(self): |
| 53 | print('usage: repo COMMAND [ARGS]') | 54 | print('usage: repo COMMAND [ARGS]') |
| 54 | print('The complete list of recognized repo commands are:') | 55 | print('The complete list of recognized repo commands are:') |
| 55 | commandNames = list(sorted(self.commands)) | 56 | commandNames = list(sorted(all_commands)) |
| 56 | self._PrintCommands(commandNames) | 57 | self._PrintCommands(commandNames) |
| 57 | print("See 'repo help <command>' for more information on a " | 58 | print("See 'repo help <command>' for more information on a " |
| 58 | 'specific command.') | 59 | 'specific command.') |
| @@ -73,7 +74,7 @@ Displays detailed usage information about a command. | |||
| 73 | return False | 74 | return False |
| 74 | 75 | ||
| 75 | commandNames = list(sorted([name | 76 | commandNames = list(sorted([name |
| 76 | for name, command in self.commands.items() | 77 | for name, command in all_commands.items() |
| 77 | if command.common and gitc_supported(command)])) | 78 | if command.common and gitc_supported(command)])) |
| 78 | self._PrintCommands(commandNames) | 79 | self._PrintCommands(commandNames) |
| 79 | 80 | ||
| @@ -132,8 +133,8 @@ Displays detailed usage information about a command. | |||
| 132 | out._PrintSection('Description', 'helpDescription') | 133 | out._PrintSection('Description', 'helpDescription') |
| 133 | 134 | ||
| 134 | def _PrintAllCommandHelp(self): | 135 | def _PrintAllCommandHelp(self): |
| 135 | for name in sorted(self.commands): | 136 | for name in sorted(all_commands): |
| 136 | cmd = self.commands[name] | 137 | cmd = all_commands[name] |
| 137 | cmd.manifest = self.manifest | 138 | cmd.manifest = self.manifest |
| 138 | self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,)) | 139 | self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,)) |
| 139 | 140 | ||
| @@ -158,7 +159,7 @@ Displays detailed usage information about a command. | |||
| 158 | name = args[0] | 159 | name = args[0] |
| 159 | 160 | ||
| 160 | try: | 161 | try: |
| 161 | cmd = self.commands[name] | 162 | cmd = all_commands[name] |
| 162 | except KeyError: | 163 | except KeyError: |
| 163 | print("repo: '%s' is not a repo command." % name, file=sys.stderr) | 164 | print("repo: '%s' is not a repo command." % name, file=sys.stderr) |
| 164 | sys.exit(1) | 165 | sys.exit(1) |
