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