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:
Steve Baker 2013-06-28 14:42:16 +12:00
parent f535cf99d0
commit 5320a3a49a
3 changed files with 11 additions and 0 deletions

View File

@ -47,6 +47,10 @@ def text_wrap_formatter(d):
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):
field_labels = field_labels or fields
pt = prettytable.PrettyTable([f for f in field_labels],

View File

@ -80,3 +80,9 @@ class shellTest(testtools.TestCase):
utils.text_wrap_formatter(
('one two three four five six seven '
'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']))

View File

@ -339,6 +339,7 @@ def do_resource_show(hc, args):
else:
formatters = {
'links': utils.link_formatter,
'required_by': utils.newline_list_formatter
}
utils.print_dict(resource.to_dict(), formatters=formatters)