From 65ad51286a2f78925f3c60c4ae989bea74221aec Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Sat, 25 Jul 2026 08:46:52 -0400 Subject: [PATCH] better handle empty headers in vertical table If the headers parameter was an empty list, the header_len calculation in vertical_table() would raise. In addition, a later zip() would have dropped elements. To fix this, synthesize header elements of only spaces, based on the first row of data, when data is also nonempty. Just in case headers and data are both empty, provide a fallback so that the header_len calculation does not raise, but computes a zero. --- CHANGELOG | 6 ++++++ cli_helpers/tabular_output/vertical_table_adapter.py | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index f6cc588..108166e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,11 @@ # Changelog +## Version 2.15.1 + +(released on 2026-07-25) + +- Better handle empty headers in vertical table output. + ## Version 2.15.0 (released on 2026-05-16) diff --git a/cli_helpers/tabular_output/vertical_table_adapter.py b/cli_helpers/tabular_output/vertical_table_adapter.py index 0b96cb2..856948e 100644 --- a/cli_helpers/tabular_output/vertical_table_adapter.py +++ b/cli_helpers/tabular_output/vertical_table_adapter.py @@ -52,7 +52,9 @@ def vertical_table( :rtype: str """ - header_len = max([len(x) for x in headers]) + if data and not headers: + headers = [" " * len(x) for x in data[0]] + header_len = max(len(x) for x in headers or [""]) padded_headers = [x.ljust(header_len) for x in headers] formatted_rows = [_format_row(padded_headers, row) for row in data]