Skip to content

Commit c8cc4b3

Browse files
Fixed failing unit tests
1 parent 301e938 commit c8cc4b3

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

linodecli/output/output_handler.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -331,27 +331,30 @@ def _json_output(self, header, data, to):
331331
# Special handling for JSON headers.
332332
# We're only interested in the last part of the column name, unless the last
333333
# part is a dotted key. If the last part is a dotted key, include the entire dotted key.
334-
parsedHeader = []
335-
terminal_keys = get_terminal_keys(data[0])
336-
337-
for v in header:
338-
parts = v.split(".")
339-
if (
340-
len(parts) >= 2
341-
and ".".join([parts[-2], parts[-1]]) in terminal_keys
342-
):
343-
parsedHeader.append(".".join([parts[-2], parts[-1]]))
344-
else:
345-
parsedHeader.append(parts[-1])
346334

347335
content = []
348336
if len(data) and isinstance(data[0], dict): # we got delimited json in
337+
parsed_header = []
338+
terminal_keys = get_terminal_keys(data[0])
339+
340+
for v in header:
341+
parts = v.split(".")
342+
if (
343+
len(parts) >= 2
344+
and ".".join([parts[-2], parts[-1]]) in terminal_keys
345+
):
346+
parsed_header.append(".".join([parts[-2], parts[-1]]))
347+
else:
348+
parsed_header.append(parts[-1])
349+
349350
# parse down to the value we display
350351
for row in data:
351-
content.append(self._select_json_elements(parsedHeader, row))
352+
content.append(self._select_json_elements(parsed_header, row))
352353
else: # this is a list
354+
header = [v.split(".")[-1] for v in header]
355+
353356
for row in data:
354-
content.append(dict(zip(parsedHeader, row)))
357+
content.append(dict(zip(header, row)))
355358

356359
print(
357360
json.dumps(

0 commit comments

Comments
 (0)