Merge "Format resource required_by in resource-show."

This commit is contained in:
Jenkins 2013-07-03 22:45:52 +00:00 committed by Gerrit Code Review
commit 9cba3dab02
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

@ -364,6 +364,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)