Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Handle a list of strings from a dict in text output #516

Merged
merged 1 commit into from

2 participants

@jamesls
Owner

This situation comes up in commands such as
aws elb describe-load-balancers. The output
now looks as expected (note the "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

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

See: https://forums.aws.amazon.com/thread.jspa?threadID=140646

@jamesls jamesls Handle a list of strings from a dict in text output
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
5ce0c9f
@garnaat

LGTM

@jamesls jamesls merged commit 5ce0c9f into aws:develop
@jamesls jamesls deleted the jamesls:text-output-list-string branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 27, 2013
  1. @jamesls

    Handle a list of strings from a dict in text output

    jamesls authored
    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
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 0 deletions.
  1. +4 −0 awscli/text.py
  2. +7 −0 tests/unit/test_text.py
View
4 awscli/text.py
@@ -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]))
View
7 tests/unit/test_text.py
@@ -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()
Something went wrong with that request. Please try again.