1
0
Fork 0

subcmds: stop instantiating at import time

The current subcmds design has singletons in all_commands.  This isn't
exactly unusual, but the fact that our main & help subcommand will then
attach members to the classes before invoking them is.  This makes it
hard to keep track of what members a command has access to, and the two
code paths (main & help) attach different members depending on what APIs
they then invoke.

Lets pull this back a step by storing classes in all_commands and leave
the instantiation step to when they're used.  This doesn't fully clean
up the confusion, but gets us closer.

Change-Id: I6a768ff97fe541e6f3228358dba04ed66c4b070a
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/259154
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
Mike Frysinger 2020-02-25 15:18:31 -05:00 committed by David Pursehouse
parent d3639c53d5
commit bb930461ce
4 changed files with 9 additions and 8 deletions

View file

@ -43,7 +43,7 @@ Displays detailed usage information about a command.
fmt = ' %%-%ds %%s' % maxlen
for name in commandNames:
command = all_commands[name]
command = all_commands[name]()
try:
summary = command.helpSummary.strip()
except AttributeError:
@ -134,7 +134,7 @@ Displays detailed usage information about a command.
def _PrintAllCommandHelp(self):
for name in sorted(all_commands):
cmd = all_commands[name]
cmd = all_commands[name]()
cmd.manifest = self.manifest
self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,))
@ -159,7 +159,7 @@ Displays detailed usage information about a command.
name = args[0]
try:
cmd = all_commands[name]
cmd = all_commands[name]()
except KeyError:
print("repo: '%s' is not a repo command." % name, file=sys.stderr)
sys.exit(1)