Merge "Update for cliff commandmanager >=1.6.1"
This commit is contained in:
commit
866965f011
@ -16,7 +16,6 @@
|
||||
"""Modify cliff.CommandManager"""
|
||||
|
||||
import logging
|
||||
import pkg_resources
|
||||
|
||||
import cliff.commandmanager
|
||||
|
||||
@ -35,23 +34,14 @@ class CommandManager(cliff.commandmanager.CommandManager):
|
||||
self.group_list = []
|
||||
super(CommandManager, self).__init__(namespace, convert_underscores)
|
||||
|
||||
def _load_commands(self, group=None):
|
||||
if not group:
|
||||
group = self.namespace
|
||||
self.group_list.append(group)
|
||||
for ep in pkg_resources.iter_entry_points(group):
|
||||
cmd_name = (
|
||||
ep.name.replace('_', ' ')
|
||||
if self.convert_underscores
|
||||
else ep.name
|
||||
)
|
||||
self.commands[cmd_name] = ep
|
||||
return
|
||||
def load_commands(self, namespace):
|
||||
self.group_list.append(namespace)
|
||||
return super(CommandManager, self).load_commands(namespace)
|
||||
|
||||
def add_command_group(self, group=None):
|
||||
"""Adds another group of command entrypoints"""
|
||||
if group:
|
||||
self._load_commands(group)
|
||||
self.load_commands(group)
|
||||
|
||||
def get_command_groups(self):
|
||||
"""Returns a list of the loaded command groups"""
|
||||
|
@ -36,15 +36,15 @@ FAKE_CMD_BETA = FakeCommand
|
||||
class FakeCommandManager(commandmanager.CommandManager):
|
||||
commands = {}
|
||||
|
||||
def _load_commands(self, group=None):
|
||||
if not group:
|
||||
def load_commands(self, namespace):
|
||||
if namespace == 'test':
|
||||
self.commands['one'] = FAKE_CMD_ONE
|
||||
self.commands['two'] = FAKE_CMD_TWO
|
||||
self.group_list.append(self.namespace)
|
||||
else:
|
||||
self.group_list.append(namespace)
|
||||
elif namespace == 'greek':
|
||||
self.commands['alpha'] = FAKE_CMD_ALPHA
|
||||
self.commands['beta'] = FAKE_CMD_BETA
|
||||
self.group_list.append(group)
|
||||
self.group_list.append(namespace)
|
||||
|
||||
|
||||
class TestCommandManager(utils.TestCase):
|
||||
@ -62,7 +62,7 @@ class TestCommandManager(utils.TestCase):
|
||||
self.assertEqual(cmd_one, FAKE_CMD_ONE)
|
||||
|
||||
# Load another command group
|
||||
mgr.add_command_group('latin')
|
||||
mgr.add_command_group('greek')
|
||||
|
||||
# Find a new command
|
||||
cmd_alpha, name, args = mgr.find_command(['alpha'])
|
||||
@ -82,7 +82,7 @@ class TestCommandManager(utils.TestCase):
|
||||
self.assertEqual(cmd_mock, mock_cmd_one)
|
||||
|
||||
# Load another command group
|
||||
mgr.add_command_group('latin')
|
||||
mgr.add_command_group('greek')
|
||||
|
||||
gl = mgr.get_command_groups()
|
||||
self.assertEqual(['test', 'latin'], gl)
|
||||
self.assertEqual(['test', 'greek'], gl)
|
||||
|
Loading…
Reference in New Issue
Block a user