summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQiu Yu <qiuyu@ebaysf.com>2014-01-15 16:51:55 +0800
committerTerry Howe <thowe@hp.com>2014-03-24 18:16:48 -0700
commite5d6b02d37c8301389feec4169b50a296a37afc3 (patch)
tree78e69ad1c0ec5809369842f9ea4057f7227c7e55
parent38e5780d2673bd4a7be702ef787b68876cc6e4dc (diff)
downloadcliff-e5d6b02d37c8301389feec4169b50a296a37afc3.tar.gz
Add max-width support for table formatter
Change-Id: If6198ede935907396454e72fc76f8ec9c1265eb6 Closes-Bug: #1269299
-rw-r--r--cliff/formatters/table.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/cliff/formatters/table.py b/cliff/formatters/table.py
index e625a25..12e1ac6 100644
--- a/cliff/formatters/table.py
+++ b/cliff/formatters/table.py
@@ -19,7 +19,14 @@ class TableFormatter(ListFormatter, SingleFormatter):
pass
def add_argument_group(self, parser):
- pass
+ group = parser.add_argument_group('table formatter')
+ group.add_argument(
+ '--max-width',
+ metavar='<integer>',
+ default=0,
+ type=int,
+ help='Maximum display width, 0 to disable',
+ )
def emit_list(self, column_names, data, stdout, parsed_args):
x = prettytable.PrettyTable(
@@ -27,6 +34,8 @@ class TableFormatter(ListFormatter, SingleFormatter):
print_empty=False,
)
x.padding_width = 1
+ if parsed_args.max_width > 0:
+ x.max_width = int(parsed_args.max_width)
# Figure out the types of the columns in the
# first row and set the alignment of the
# output accordingly.
@@ -52,6 +61,8 @@ class TableFormatter(ListFormatter, SingleFormatter):
x = prettytable.PrettyTable(field_names=('Field', 'Value'),
print_empty=False)
x.padding_width = 1
+ if parsed_args.max_width > 0:
+ x.max_width = int(parsed_args.max_width)
# Align all columns left because the values are
# not all the same type.
x.align['Field'] = 'l'