From 755f609c31e735fa6abd030a6bdabb2fb36c6875 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Wed, 11 Jun 2014 11:35:10 +0100 Subject: [PATCH] Add rel field to links display Currently the "rel" keys from the links list are not displayed, so it's not that clear which link refers to what unless you're familiar with heat. So add a suffix which mentions the rel so e.g users can see "nested" there and tell the link refers to a nested stack. Change-Id: I5abe7f7b51c290bd9d8daaccb7f9a842af898f58 --- heatclient/common/utils.py | 7 ++++++- heatclient/tests/test_utils.py | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/heatclient/common/utils.py b/heatclient/common/utils.py index 901b5262..89e4b4a8 100644 --- a/heatclient/common/utils.py +++ b/heatclient/common/utils.py @@ -37,7 +37,12 @@ print_list = cliutils.print_list def link_formatter(links): - return '\n'.join([l.get('href', '') for l in links or []]) + def format_link(l): + if 'rel' in l: + return "%s (%s)" % (l.get('href', ''), l.get('rel', '')) + else: + return "%s" % (l.get('href', '')) + return '\n'.join(format_link(l) for l in links or []) def json_formatter(js): diff --git a/heatclient/tests/test_utils.py b/heatclient/tests/test_utils.py index bd8d55dc..85be4d23 100644 --- a/heatclient/tests/test_utils.py +++ b/heatclient/tests/test_utils.py @@ -96,6 +96,11 @@ class shellTest(testtools.TestCase): utils.link_formatter([ {'href': 'http://foo.example.com'}, {'href': 'http://bar.example.com'}])) + self.assertEqual( + 'http://foo.example.com (a)\nhttp://bar.example.com (b)', + utils.link_formatter([ + {'href': 'http://foo.example.com', 'rel': 'a'}, + {'href': 'http://bar.example.com', 'rel': 'b'}])) self.assertEqual( '\n', utils.link_formatter([