mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
f725e548db
commit
d3639c53d5
2
main.py
2
main.py
@ -135,8 +135,6 @@ class _Repo(object):
|
|||||||
def __init__(self, repodir):
|
def __init__(self, repodir):
|
||||||
self.repodir = repodir
|
self.repodir = repodir
|
||||||
self.commands = all_commands
|
self.commands = all_commands
|
||||||
# add 'branch' as an alias for 'branches'
|
|
||||||
all_commands['branch'] = all_commands['branches']
|
|
||||||
|
|
||||||
def _ParseArgs(self, argv):
|
def _ParseArgs(self, argv):
|
||||||
"""Parse the main `repo` command line options."""
|
"""Parse the main `repo` command line options."""
|
||||||
|
@ -46,5 +46,5 @@ for py in os.listdir(my_dir):
|
|||||||
cmd.NAME = name
|
cmd.NAME = name
|
||||||
all_commands[name] = cmd
|
all_commands[name] = cmd
|
||||||
|
|
||||||
if 'help' in all_commands:
|
# Add 'branch' as an alias for 'branches'.
|
||||||
all_commands['help'].commands = all_commands
|
all_commands['branch'] = all_commands['branches']
|
||||||
|
@ -19,6 +19,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
from formatter import AbstractFormatter, DumbWriter
|
from formatter import AbstractFormatter, DumbWriter
|
||||||
|
|
||||||
|
from subcmds import all_commands
|
||||||
from color import Coloring
|
from color import Coloring
|
||||||
from command import PagedCommand, MirrorSafeCommand, GitcAvailableCommand, GitcClientCommand
|
from command import PagedCommand, MirrorSafeCommand, GitcAvailableCommand, GitcClientCommand
|
||||||
import gitc_utils
|
import gitc_utils
|
||||||
@ -42,7 +43,7 @@ Displays detailed usage information about a command.
|
|||||||
fmt = ' %%-%ds %%s' % maxlen
|
fmt = ' %%-%ds %%s' % maxlen
|
||||||
|
|
||||||
for name in commandNames:
|
for name in commandNames:
|
||||||
command = self.commands[name]
|
command = all_commands[name]
|
||||||
try:
|
try:
|
||||||
summary = command.helpSummary.strip()
|
summary = command.helpSummary.strip()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@ -52,7 +53,7 @@ Displays detailed usage information about a command.
|
|||||||
def _PrintAllCommands(self):
|
def _PrintAllCommands(self):
|
||||||
print('usage: repo COMMAND [ARGS]')
|
print('usage: repo COMMAND [ARGS]')
|
||||||
print('The complete list of recognized repo commands are:')
|
print('The complete list of recognized repo commands are:')
|
||||||
commandNames = list(sorted(self.commands))
|
commandNames = list(sorted(all_commands))
|
||||||
self._PrintCommands(commandNames)
|
self._PrintCommands(commandNames)
|
||||||
print("See 'repo help <command>' for more information on a "
|
print("See 'repo help <command>' for more information on a "
|
||||||
'specific command.')
|
'specific command.')
|
||||||
@ -73,7 +74,7 @@ Displays detailed usage information about a command.
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
commandNames = list(sorted([name
|
commandNames = list(sorted([name
|
||||||
for name, command in self.commands.items()
|
for name, command in all_commands.items()
|
||||||
if command.common and gitc_supported(command)]))
|
if command.common and gitc_supported(command)]))
|
||||||
self._PrintCommands(commandNames)
|
self._PrintCommands(commandNames)
|
||||||
|
|
||||||
@ -132,8 +133,8 @@ Displays detailed usage information about a command.
|
|||||||
out._PrintSection('Description', 'helpDescription')
|
out._PrintSection('Description', 'helpDescription')
|
||||||
|
|
||||||
def _PrintAllCommandHelp(self):
|
def _PrintAllCommandHelp(self):
|
||||||
for name in sorted(self.commands):
|
for name in sorted(all_commands):
|
||||||
cmd = self.commands[name]
|
cmd = all_commands[name]
|
||||||
cmd.manifest = self.manifest
|
cmd.manifest = self.manifest
|
||||||
self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,))
|
self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,))
|
||||||
|
|
||||||
@ -158,7 +159,7 @@ Displays detailed usage information about a command.
|
|||||||
name = args[0]
|
name = args[0]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmd = self.commands[name]
|
cmd = all_commands[name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print("repo: '%s' is not a repo command." % name, file=sys.stderr)
|
print("repo: '%s' is not a repo command." % name, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user