diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-03-28 18:50:02 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-03-28 18:50:02 +0000 |
commit | 26335cbcfb622dcb8e5dc8ef54b0b22a1d73c527 (patch) | |
tree | 56f5ba2818b0e9b4ad07c23b23a6da0ccdfe308f | |
parent | 5503d3d0068484b7428e223011733667eb4e347f (diff) | |
parent | e5d6b02d37c8301389feec4169b50a296a37afc3 (diff) | |
download | cliff-26335cbcfb622dcb8e5dc8ef54b0b22a1d73c527.tar.gz |
Merge "Add max-width support for table formatter"1.6.0
-rw-r--r-- | cliff/formatters/table.py | 13 |
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' |