Merge "Add rel field to links display"
This commit is contained in:
@@ -37,7 +37,12 @@ print_list = cliutils.print_list
|
|||||||
|
|
||||||
|
|
||||||
def link_formatter(links):
|
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):
|
def json_formatter(js):
|
||||||
|
|||||||
@@ -96,6 +96,11 @@ class shellTest(testtools.TestCase):
|
|||||||
utils.link_formatter([
|
utils.link_formatter([
|
||||||
{'href': 'http://foo.example.com'},
|
{'href': 'http://foo.example.com'},
|
||||||
{'href': 'http://bar.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(
|
self.assertEqual(
|
||||||
'\n',
|
'\n',
|
||||||
utils.link_formatter([
|
utils.link_formatter([
|
||||||
|
|||||||
Reference in New Issue
Block a user