summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/common/commandmanager.py18
-rw-r--r--openstackclient/tests/common/test_commandmanager.py19
2 files changed, 34 insertions, 3 deletions
diff --git a/openstackclient/common/commandmanager.py b/openstackclient/common/commandmanager.py
index 06073d93..553bc920 100644
--- a/openstackclient/common/commandmanager.py
+++ b/openstackclient/common/commandmanager.py
@@ -1,4 +1,4 @@
-# Copyright 2012-2013 OpenStack, LLC.
+# Copyright 2012-2013 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@@ -28,15 +28,29 @@ class CommandManager(cliff.commandmanager.CommandManager):
"""Alters Cliff's default CommandManager behaviour to load additional
command groups after initialization.
"""
+ def __init__(self, namespace, convert_underscores=True):
+ 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):
LOG.debug('found command %r' % ep.name)
- self.commands[ep.name.replace('_', ' ')] = ep
+ 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):
"""Adds another group of command entrypoints"""
if group:
self._load_commands(group)
+
+ def get_command_groups(self):
+ """Returns a list of the loaded command groups"""
+ return self.group_list
diff --git a/openstackclient/tests/common/test_commandmanager.py b/openstackclient/tests/common/test_commandmanager.py
index 4953c297..088ea21e 100644
--- a/openstackclient/tests/common/test_commandmanager.py
+++ b/openstackclient/tests/common/test_commandmanager.py
@@ -1,4 +1,4 @@
-# Copyright 2012-2013 OpenStack, LLC.
+# Copyright 2012-2013 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@@ -40,9 +40,11 @@ class FakeCommandManager(commandmanager.CommandManager):
if not group:
self.commands['one'] = FAKE_CMD_ONE
self.commands['two'] = FAKE_CMD_TWO
+ self.group_list.append(self.namespace)
else:
self.commands['alpha'] = FAKE_CMD_ALPHA
self.commands['beta'] = FAKE_CMD_BETA
+ self.group_list.append(group)
class TestCommandManager(utils.TestCase):
@@ -69,3 +71,18 @@ class TestCommandManager(utils.TestCase):
# Ensure that the original commands were not overwritten
cmd_two, name, args = mgr.find_command(['two'])
self.assertEqual(cmd_two, FAKE_CMD_TWO)
+
+ def test_get_command_groups(self):
+ mgr = FakeCommandManager('test')
+
+ # Make sure add_command() still functions
+ mock_cmd_one = mock.Mock()
+ mgr.add_command('mock', mock_cmd_one)
+ cmd_mock, name, args = mgr.find_command(['mock'])
+ self.assertEqual(cmd_mock, mock_cmd_one)
+
+ # Load another command group
+ mgr.add_command_group('latin')
+
+ gl = mgr.get_command_groups()
+ self.assertEqual(['test', 'latin'], gl)