From 5320a3a49ad15f129c420ffdbab66c3a0e5626c9 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Fri, 28 Jun 2013 14:42:16 +1200 Subject: [PATCH] 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 --- heatclient/common/utils.py | 4 ++++ heatclient/tests/test_utils.py | 6 ++++++ heatclient/v1/shell.py | 1 + 3 files changed, 11 insertions(+) diff --git a/heatclient/common/utils.py b/heatclient/common/utils.py index 85eed929..f22fba38 100644 --- a/heatclient/common/utils.py +++ b/heatclient/common/utils.py @@ -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], diff --git a/heatclient/tests/test_utils.py b/heatclient/tests/test_utils.py index 682b5625..3de7aab4 100644 --- a/heatclient/tests/test_utils.py +++ b/heatclient/tests/test_utils.py @@ -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'])) diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index b895e876..7c0b2c03 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -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)