Handle empty name case when splitting description field in help (#5941)

This commit is contained in:
Jakub Kuczys 2023-06-19 14:15:34 +02:00 committed by GitHub
parent 30dc128c39
commit be5751a7ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -398,13 +398,18 @@ class RedHelpFormatter(HelpFormatterABC):
command_help = command.format_help_for_context(ctx)
if command_help:
splitted = command_help.split("\n\n")
name = splitted[0]
value = "\n\n".join(splitted[1:])
if not value:
value = EMPTY_STRING
field = EmbedField(name[:250], value[:1024], False)
emb["fields"].append(field)
splitted = filter(None, command_help.split("\n\n"))
try:
name = next(splitted)
except StopIteration:
# all parts are empty
pass
else:
value = "\n\n".join(splitted)
if not value:
value = EMPTY_STRING
field = EmbedField(name[:250], value[:1024], False)
emb["fields"].append(field)
if subcommands:
@ -571,13 +576,18 @@ class RedHelpFormatter(HelpFormatterABC):
emb["footer"]["text"] = tagline
if description:
splitted = description.split("\n\n")
name = splitted[0]
value = "\n\n".join(splitted[1:])
if not value:
value = EMPTY_STRING
field = EmbedField(name[:252], value[:1024], False)
emb["fields"].append(field)
splitted = filter(None, description.split("\n\n"))
try:
name = next(splitted)
except StopIteration:
# all parts are empty
pass
else:
value = "\n\n".join(splitted)
if not value:
value = EMPTY_STRING
field = EmbedField(name[:252], value[:1024], False)
emb["fields"].append(field)
if coms: