Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions fire/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ def WrappedJoin(items, separator=' | ', width=80):
if len(current_line) + len(item) <= width:
current_line += item
else:
lines.append(current_line.rstrip())
if current_line:
lines.append(current_line.rstrip())
current_line = item
else:
if len(current_line) + len(item) + len(separator) <= width:
current_line += item + separator
else:
lines.append(current_line.rstrip())
if current_line:
lines.append(current_line.rstrip())
current_line = item + separator

lines.append(current_line)
Expand Down
13 changes: 13 additions & 0 deletions fire/formatting_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ def test_wrap_multiple_items(self):
'chicken |',
'cheese'], lines)

def test_wrap_first_item_longer_than_width(self):
self.assertEqual(
['long_command'],
formatting.WrappedJoin(['long_command'], width=5))
self.assertEqual(
['long_command |', 'next'],
formatting.WrappedJoin(['long_command', 'next'], width=5))

def test_wrap_first_item_separator_exceeds_width(self):
self.assertEqual(
['first |', 'next'],
formatting.WrappedJoin(['first', 'next'], width=5))

def test_ellipsis_truncate(self):
text = 'This is a string'
truncated_text = formatting.EllipsisTruncate(
Expand Down
7 changes: 7 additions & 0 deletions fire/helptext_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,13 @@ def testHelpTextMultipleKeywoardArgumentsWithShortArgs(self):

class UsageTest(testutils.BaseTestCase):

def testAvailabilityLineWithLongFirstCommand(self):
# pylint: disable=protected-access
availability_line = helptext._CreateAvailabilityLine(
'COMMANDS', ['long_command'], line_length=30)
self.assertEqual(
' COMMANDS' + ' ' * 15 + 'long_command\n', availability_line)

def testUsageOutput(self):
component = tc.NoDefaults()
t = trace.FireTrace(component, name='NoDefaults')
Expand Down
Loading