Skip to content

Commit

Permalink
Handle a list of strings from a dict in text output
Browse files Browse the repository at this point in the history
This situation comes up in commands such as
`aws ec2 describe-load-balancers`.  The output
now looks as expected:

Now:
AVAILABILITYZONES	us-west-2a
HEALTHCHECK	10	30	HTTP:80/index.html	5	2
LISTENER	80	HTTP	80	HTTP
SOURCESECURITYGROUP	amazon-elb-sg	amazon-elb
LOADBALANCERDESCRIPTIONS		a	b	c	d
AVAILABILITYZONES	us-west-2b

Before:

AVAILABILITYZONES	us-west-2a
HEALTHCHECK	10	30	HTTP:80/index.html	5	2
LISTENER	80	HTTP	80	HTTP
SOURCESECURITYGROUP	amazon-elb-sg	amazon-elb
LOADBALANCERDESCRIPTIONS		a	b	c	d
us-west-2b
  • Loading branch information
jamesls committed Nov 27, 2013
1 parent 968dc0e commit 5ce0c9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions awscli/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def _format_text(item, stream, identifier=None, scalar_keys=None):
for list_element in item:
_format_text(list_element, stream=stream,
identifier=identifier)
elif identifier is not None:
for list_element in item:
stream.write('%s\t%s\n' % (identifier.upper(),
list_element))
else:
# For a bare list, just print the contents.
stream.write('\t'.join([six.text_type(el) for el in item]))
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ def test_empty_list_mock_calls(self):
# We should not call .write() at all for an empty list.
self.assertFalse(fake_stream.write.called)

def test_list_of_strings_in_dict(self):
self.assert_text_renders_to(
{"KeyName": ['a', 'b', 'c']},
'KEYNAME\ta\n'
'KEYNAME\tb\n'
'KEYNAME\tc\n')


if __name__ == '__main__':
unittest.main()

0 comments on commit 5ce0c9f

Please sign in to comment.