Sitelet https://github.com/outcoldman/aws-cli/commit/fb3cc1757b068816a0296146110c52cbe024c64d
Skip to content

Commit fb3cc17

Browse files
committed
Recursively process list elements in text output
1 parent 70b7d72 commit fb3cc17

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎awscli/text.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def _format_text(item, stream, identifier=None, scalar_keys=None):
3535
stream=stream,
3636
identifier=identifier,
3737
scalar_keys=all_keys)
38+
elif isinstance(item[0], list):
39+
for list_element in item:
40+
_format_text(list_element, stream=stream,
41+
identifier=identifier)
3842
else:
3943
# For a bare list, just print the contents.
4044
stream.write('\t'.join([str(el) for el in item]))

‎tests/unit/test_text.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,25 @@ def test_scalars_and_complex_types(self):
8888
'FOO\t4\t6\n'
8989
'B\ty\tz\n')
9090

91+
def test_nested_list_of_lists(self):
92+
self.assert_text_renders_to(
93+
[['1', '2', '3'], ['4', '5', '6']],
94+
'1\t2\t3\n'
95+
'4\t5\t6\n'
96+
)
97+
98+
def test_deeply_nested_lists(self):
99+
self.assert_text_renders_to(
100+
[
101+
[['1', '2', '3'], ['4', '5', '6']],
102+
[['7', '8', '9'], ['0', '1', '2']],
103+
],
104+
'1\t2\t3\n'
105+
'4\t5\t6\n'
106+
'7\t8\t9\n'
107+
'0\t1\t2\n'
108+
)
109+
91110

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

0 commit comments

Comments
 (0)