Format resource required_by in resource-show.
This change has no effect if the resource details contains no requires key (such as for older API versions). Change-Id: I5bce5cf6a7c7cd3f531453cd126fb7b7b3e227ef
This commit is contained in:
parent
f535cf99d0
commit
5320a3a49a
@ -47,6 +47,10 @@ def text_wrap_formatter(d):
|
|||||||
return '\n'.join(textwrap.wrap(d or '', 55))
|
return '\n'.join(textwrap.wrap(d or '', 55))
|
||||||
|
|
||||||
|
|
||||||
|
def newline_list_formatter(r):
|
||||||
|
return '\n'.join(r or [])
|
||||||
|
|
||||||
|
|
||||||
def print_list(objs, fields, field_labels=None, formatters={}, sortby=0):
|
def print_list(objs, fields, field_labels=None, formatters={}, sortby=0):
|
||||||
field_labels = field_labels or fields
|
field_labels = field_labels or fields
|
||||||
pt = prettytable.PrettyTable([f for f in field_labels],
|
pt = prettytable.PrettyTable([f for f in field_labels],
|
||||||
|
@ -80,3 +80,9 @@ class shellTest(testtools.TestCase):
|
|||||||
utils.text_wrap_formatter(
|
utils.text_wrap_formatter(
|
||||||
('one two three four five six seven '
|
('one two three four five six seven '
|
||||||
'eight nine ten eleven twelve')))
|
'eight nine ten eleven twelve')))
|
||||||
|
|
||||||
|
def test_newline_list_formatter(self):
|
||||||
|
self.assertEqual('', utils.newline_list_formatter(None))
|
||||||
|
self.assertEqual('', utils.newline_list_formatter([]))
|
||||||
|
self.assertEqual('one\ntwo',
|
||||||
|
utils.newline_list_formatter(['one', 'two']))
|
||||||
|
@ -339,6 +339,7 @@ def do_resource_show(hc, args):
|
|||||||
else:
|
else:
|
||||||
formatters = {
|
formatters = {
|
||||||
'links': utils.link_formatter,
|
'links': utils.link_formatter,
|
||||||
|
'required_by': utils.newline_list_formatter
|
||||||
}
|
}
|
||||||
utils.print_dict(resource.to_dict(), formatters=formatters)
|
utils.print_dict(resource.to_dict(), formatters=formatters)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user