Skip to content

Commit ec1997a

Browse files
Merge pull request #1689 from allmightyspiff/issues1686
Enable --format=raw and fixes table width
2 parents 02184d3 + aea1a6e commit ec1997a

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

SoftLayer/CLI/environment.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def __init__(self):
4545

4646
def out(self, output):
4747
"""Outputs a string to the console (stdout)."""
48+
49+
# If we output to a | or file, need to set default width so all output is printed.
50+
if not self.console.is_terminal:
51+
self.console.width = 1000000
4852
if self.format == 'json':
4953
try:
5054
self.console.print_json(output)

SoftLayer/CLI/formatting.py

Lines changed: 8 additions & 6 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

@@ -208,7 +208,6 @@ def to_python(self):
208208
return self
209209

210210
def __str__(self):
211-
print("CASTSDFSDFSDFSDFSDF")
212211
return self.separator.join(str(x) for x in self)
213212

214213

@@ -258,9 +257,12 @@ def to_python(self):
258257
items.append(dict(zip(self.columns, formatted_row)))
259258
return items
260259

261-
def prettytable(self):
260+
def prettytable(self, fmt='table'):
262261
"""Returns a RICH table instance."""
263-
table = rTable(title=self.title, box=box.SQUARE, header_style="bright_cyan")
262+
box_style = box.SQUARE
263+
if fmt == 'raw':
264+
box_style = None
265+
table = rTable(title=self.title, box=box_style, header_style="bright_cyan")
264266
if self.sortby:
265267
try:
266268
# 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)