Merge "Improve output for "os security group show""
This commit is contained in:
openstackclient
@ -154,14 +154,15 @@ def format_dict(data):
|
|||||||
return output[:-2]
|
return output[:-2]
|
||||||
|
|
||||||
|
|
||||||
def format_list(data):
|
def format_list(data, separator=', '):
|
||||||
"""Return a formatted strings
|
"""Return a formatted strings
|
||||||
|
|
||||||
:param data: a list of strings
|
:param data: a list of strings
|
||||||
:rtype: a string formatted to a,b,c
|
:param separator: the separator to use between strings (default: ', ')
|
||||||
|
:rtype: a string formatted based on separator
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return ', '.join(sorted(data))
|
return separator.join(sorted(data))
|
||||||
|
|
||||||
|
|
||||||
def get_field(item, field):
|
def get_field(item, field):
|
||||||
|
@ -390,7 +390,7 @@ class ShowSecurityGroup(show.ShowOne):
|
|||||||
|
|
||||||
# Format rules into a list of strings
|
# Format rules into a list of strings
|
||||||
info.update(
|
info.update(
|
||||||
{'rules': rules}
|
{'rules': utils.format_list(rules, separator='\n')}
|
||||||
)
|
)
|
||||||
# Map 'tenant_id' column to 'project_id'
|
# Map 'tenant_id' column to 'project_id'
|
||||||
info.update(
|
info.update(
|
||||||
|
@ -347,3 +347,10 @@ class TestFindResource(test_utils.TestCase):
|
|||||||
expected = 'a, b, c'
|
expected = 'a, b, c'
|
||||||
self.assertEqual(expected, utils.format_list(['a', 'b', 'c']))
|
self.assertEqual(expected, utils.format_list(['a', 'b', 'c']))
|
||||||
self.assertEqual(expected, utils.format_list(['c', 'b', 'a']))
|
self.assertEqual(expected, utils.format_list(['c', 'b', 'a']))
|
||||||
|
|
||||||
|
def test_format_list_separator(self):
|
||||||
|
expected = 'a\nb\nc'
|
||||||
|
actual_pre_sorted = utils.format_list(['a', 'b', 'c'], separator='\n')
|
||||||
|
actual_unsorted = utils.format_list(['c', 'b', 'a'], separator='\n')
|
||||||
|
self.assertEqual(expected, actual_pre_sorted)
|
||||||
|
self.assertEqual(expected, actual_unsorted)
|
||||||
|
Reference in New Issue
Block a user