Skip to content

Commit eede587

Browse files
#1686 added back support for --raw output format
1 parent 119d2b3 commit eede587

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

SoftLayer/CLI/formatting.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def format_output(data, fmt='table'): # pylint: disable=R0911,R0912
3535

3636
# responds to .prettytable()
3737
if hasattr(data, 'prettytable') and fmt in ('table', 'raw'):
38-
return format_prettytable(data)
38+
return format_prettytable(data, fmt)
3939

4040
# responds to .to_python()
4141
if hasattr(data, 'to_python'):
@@ -68,12 +68,12 @@ def format_output(data, fmt='table'): # pylint: disable=R0911,R0912
6868
return str(data)
6969

7070

71-
def format_prettytable(table):
71+
def format_prettytable(table, fmt='table'):
7272
"""Converts SoftLayer.CLI.formatting.Table instance to a prettytable."""
7373
for i, row in enumerate(table.rows):
7474
for j, item in enumerate(row):
7575
table.rows[i][j] = format_output(item)
76-
ptable = table.prettytable()
76+
ptable = table.prettytable(fmt)
7777
return ptable
7878

7979

@@ -258,9 +258,12 @@ def to_python(self):
258258
items.append(dict(zip(self.columns, formatted_row)))
259259
return items
260260

261-
def prettytable(self):
261+
def prettytable(self, fmt='table'):
262262
"""Returns a RICH table instance."""
263-
table = rTable(title=self.title, box=box.SQUARE, header_style="bright_cyan")
263+
box_style = box.SQUARE
264+
if fmt == 'raw':
265+
box_style = None
266+
table = rTable(title=self.title, box=box_style, header_style="bright_cyan")
264267
if self.sortby:
265268
try:
266269
# https://docs.python.org/3/howto/sorting.html#key-functions

tests/CLI/helper_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ def test_format_output_table_invalid_sort(self):
396396
formatting.format_output, t, 'table',
397397
)
398398

399+
def test_format_raw_table(self):
400+
test_table = formatting.Table(['col1', 'col2'])
401+
test_table.add_row(['row1', 'row2'])
402+
pretty_table = formatting.format_output(test_table, 'raw')
403+
self.assertIsNone(pretty_table.box)
404+
399405

400406
class TestTemplateArgs(testing.TestCase):
401407

0 commit comments

Comments
 (0)