Skip to content

Commit f0c3b4e

Browse files
author
Brandon Palm
committed
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
1 parent 040d0c2 commit f0c3b4e

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

openstackclient/common/module.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import sys
2020

2121
from openstackclient.common import command
22+
from openstackclient.common import utils
2223

2324

2425
class ListCommand(command.Lister):
@@ -29,9 +30,24 @@ class ListCommand(command.Lister):
2930
def take_action(self, parsed_args):
3031
cm = self.app.command_manager
3132
groups = cm.get_command_groups()
32-
33+
groups = sorted(groups)
3334
columns = ('Command Group', 'Commands')
34-
return (columns, ((c, cm.get_command_names(group=c)) for c in groups))
35+
36+
commands = []
37+
for group in groups:
38+
command_names = cm.get_command_names(group)
39+
command_names = sorted(command_names)
40+
41+
if command_names != []:
42+
43+
# TODO(bapalm): Fix this when cliff properly supports
44+
# handling the detection rather than using the hard-code below.
45+
if parsed_args.formatter == 'table':
46+
command_names = utils.format_list(command_names, "\n")
47+
48+
commands.append((group, command_names))
49+
50+
return (columns, commands)
3551

3652

3753
class ListModule(command.ShowOne):

openstackclient/tests/common/test_module.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ def setUp(self):
4848
super(TestCommandList, self).setUp()
4949

5050
self.app.command_manager = mock.Mock()
51-
self.app.command_manager.get_command_groups.return_value = ['test']
51+
self.app.command_manager.get_command_groups.return_value = [
52+
'openstack.common'
53+
]
5254
self.app.command_manager.get_command_names.return_value = [
53-
'one',
54-
'cmd two',
55+
'limits show\nextension list'
5556
]
5657

5758
# Get the command object to test
@@ -67,12 +68,15 @@ def test_command_list_no_options(self):
6768
# containing the data to be listed.
6869
columns, data = self.cmd.take_action(parsed_args)
6970

71+
# TODO(bapalm): Adjust this when cliff properly supports
72+
# handling the detection rather than using the hard-code below.
7073
collist = ('Command Group', 'Commands')
7174
self.assertEqual(collist, columns)
7275
datalist = ((
73-
'test',
74-
['one', 'cmd two'],
75-
), )
76+
'openstack.common',
77+
'limits show\nextension list'
78+
),)
79+
7680
self.assertEqual(datalist, tuple(data))
7781

7882

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed ``openstack command list`` to display properly
5+
[Bug `1545609 <https://bugs.launchpad.net/python-openstackclient/+bug/1545609>`_]

0 commit comments

Comments
 (0)