diff options
author | Doug Hellmann <doug@doughellmann.com> | 2016-02-11 16:31:43 -0500 |
---|---|---|
committer | Doug Hellmann <doug@doughellmann.com> | 2016-02-11 16:32:23 -0500 |
commit | c96658875af585cfaf3aed9a60dc5f27d218241b (patch) | |
tree | bbd9c156d0288529949b2a66ccaf43dd6d0525b0 /cliff/formatters | |
parent | 297f8b81558be17a4e25816f28c4cf6f8557b240 (diff) | |
download | cliff-c96658875af585cfaf3aed9a60dc5f27d218241b.tar.gz |
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 <doug@doughellmann.com>
Diffstat (limited to 'cliff/formatters')
-rw-r--r-- | cliff/formatters/table.py | 7 |
1 files changed, 5 insertions, 2 deletions
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( |