From f0c3b4e69dc56934305442b505d5f5f68579f1f2 Mon Sep 17 00:00:00 2001 From: Brandon Palm Date: Wed, 17 Feb 2016 20:01:23 +0000 Subject: [PATCH] Fixed command list The cliff module expects an array of tuples however the array that this function was returning was an array of tuples that was also containing an array of values for the commands attached to each group and the cliff module wasn't liking it. The output now comes out looking like: | openstack.common | limits show | | | extension list | | openstack.baremetal.v1 | baremetal set | Change-Id: Ifa1c149cb5c66ba27dc72bf72d7c8f2f50e42f73 Closes-Bug: 1545609 --- openstackclient/common/module.py | 20 +++++++++++++++++-- openstackclient/tests/common/test_module.py | 16 +++++++++------ .../notes/bug-1545609-bdc1efc17214463b.yaml | 5 +++++ 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 releasenotes/notes/bug-1545609-bdc1efc17214463b.yaml diff --git a/openstackclient/common/module.py b/openstackclient/common/module.py index a3dea5da50..30c67c683f 100644 --- a/openstackclient/common/module.py +++ b/openstackclient/common/module.py @@ -19,6 +19,7 @@ import six import sys from openstackclient.common import command +from openstackclient.common import utils class ListCommand(command.Lister): @@ -29,9 +30,24 @@ class ListCommand(command.Lister): def take_action(self, parsed_args): cm = self.app.command_manager groups = cm.get_command_groups() - + groups = sorted(groups) columns = ('Command Group', 'Commands') - return (columns, ((c, cm.get_command_names(group=c)) for c in groups)) + + commands = [] + for group in groups: + command_names = cm.get_command_names(group) + command_names = sorted(command_names) + + if command_names != []: + + # TODO(bapalm): Fix this when cliff properly supports + # handling the detection rather than using the hard-code below. + if parsed_args.formatter == 'table': + command_names = utils.format_list(command_names, "\n") + + commands.append((group, command_names)) + + return (columns, commands) class ListModule(command.ShowOne): diff --git a/openstackclient/tests/common/test_module.py b/openstackclient/tests/common/test_module.py index 2821da9ed7..7d08dae7b7 100644 --- a/openstackclient/tests/common/test_module.py +++ b/openstackclient/tests/common/test_module.py @@ -48,10 +48,11 @@ class TestCommandList(utils.TestCommand): super(TestCommandList, self).setUp() self.app.command_manager = mock.Mock() - self.app.command_manager.get_command_groups.return_value = ['test'] + self.app.command_manager.get_command_groups.return_value = [ + 'openstack.common' + ] self.app.command_manager.get_command_names.return_value = [ - 'one', - 'cmd two', + 'limits show\nextension list' ] # Get the command object to test @@ -67,12 +68,15 @@ class TestCommandList(utils.TestCommand): # containing the data to be listed. columns, data = self.cmd.take_action(parsed_args) + # TODO(bapalm): Adjust this when cliff properly supports + # handling the detection rather than using the hard-code below. collist = ('Command Group', 'Commands') self.assertEqual(collist, columns) datalist = (( - 'test', - ['one', 'cmd two'], - ), ) + 'openstack.common', + 'limits show\nextension list' + ),) + self.assertEqual(datalist, tuple(data)) diff --git a/releasenotes/notes/bug-1545609-bdc1efc17214463b.yaml b/releasenotes/notes/bug-1545609-bdc1efc17214463b.yaml new file mode 100644 index 0000000000..73ce8db09a --- /dev/null +++ b/releasenotes/notes/bug-1545609-bdc1efc17214463b.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixed ``openstack command list`` to display properly + [Bug `1545609 `_]