From c96658875af585cfaf3aed9a60dc5f27d218241b Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 11 Feb 2016 16:31:43 -0500 Subject: handle empty list in table formatter If there is no data to be formatted, don't try to make sure it fits in the width of the terminal because we're not going to be writing anything anyway. Closes-Bug: #1539770 Change-Id: I877bad1be7a074fccc03f0327b0e43f1e125246c Signed-off-by: Doug Hellmann --- cliff/formatters/table.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'cliff/formatters') diff --git a/cliff/formatters/table.py b/cliff/formatters/table.py index 43c1ed6..d146276 100644 --- a/cliff/formatters/table.py +++ b/cliff/formatters/table.py @@ -145,8 +145,11 @@ class TableFormatter(ListFormatter, SingleFormatter): return field_count = len(x.field_names) - first_line = x.get_string().splitlines()[0] - if len(first_line) <= term_width: + try: + first_line = x.get_string().splitlines()[0] + if len(first_line) <= term_width: + return + except IndexError: return usable_total_width, optimal_width = TableFormatter._width_info( -- cgit v1.2.1