Fix pagination of huge command help messages (> ~2,000 chars)

Previously, calls to add_line in add_command_formatting of default help
commands would fail if the command's help message would overflow the
current page. This would also result in silent failure as the
RuntimeError raised from add_line is never caught.

This patch adds behavior that adds lines individually should it raise,
which guarantees safe pagination as long as every line is smaller than
the maximum page size, which is highly unlikely.
This commit is contained in:
slice 2019-03-16 20:24:31 -07:00 committed by Danny
parent 682c0d962f
commit 66af80511f

View File

@ -889,7 +889,12 @@ class DefaultHelpCommand(HelpCommand):
self.paginator.add_line(signature, empty=True)
if command.help:
self.paginator.add_line(command.help, empty=True)
try:
self.paginator.add_line(command.help, empty=True)
except RuntimeError:
for line in command.help.splitlines():
self.paginator.add_line(line)
self.paginator.add_line()
def get_destination(self):
ctx = self.context
@ -1115,7 +1120,12 @@ class MinimalHelpCommand(HelpCommand):
self.paginator.add_line(signature, empty=True)
if command.help:
self.paginator.add_line(command.help, empty=True)
try:
self.paginator.add_line(command.help, empty=True)
except RuntimeError:
for line in command.help.splitlines():
self.paginator.add_line(line)
self.paginator.add_line()
def get_destination(self):
ctx = self.context