Update for cliff commandmanager >=1.6.1

Cliff 1.6.1 added  CommandManager.load_commands() so we can adopt it
rather than rolling our own.

Also, that second group is Greek, not Latin.  Jeez...

Change-Id: I4a63c22f37bcfd0ef5d83c2dbd08b58fda0db35c
This commit is contained in:
Dean Troyer 2014-06-26 17:23:59 -05:00
parent 0cb204e59b
commit 5b6c24fdb0
2 changed files with 12 additions and 22 deletions

View File

@ -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"""

View File

@ -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)