fix: indent docstring body in help paste output
Command name stays flush-left, docstring lines indented 4 spaces. Plugin descriptions in the full reference also indented under headers. Adds test_help_paste_body_indented to verify formatting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,14 +9,18 @@ from derp.plugin import command
|
||||
|
||||
|
||||
def _build_cmd_detail(handler, prefix: str) -> str:
|
||||
"""Extract and format a command's docstring into a detail block."""
|
||||
"""Extract and format a command's docstring into a detail block.
|
||||
|
||||
Command name anchors the left edge; docstring body is indented 4 spaces.
|
||||
"""
|
||||
doc = textwrap.dedent(handler.callback.__doc__ or "").strip()
|
||||
if not doc:
|
||||
return ""
|
||||
header = f"{prefix}{handler.name}"
|
||||
if handler.help:
|
||||
header += f" -- {handler.help}"
|
||||
return f"{header}\n{doc}"
|
||||
indented = textwrap.indent(doc, " ")
|
||||
return f"{header}\n{indented}"
|
||||
|
||||
|
||||
async def _paste(bot, text: str) -> str | None:
|
||||
@@ -108,7 +112,7 @@ async def cmd_help(bot, message):
|
||||
desc = (getattr(mod, "__doc__", "") or "").split("\n")[0].strip() if mod else ""
|
||||
header = f"[{plugin_name}]"
|
||||
if desc:
|
||||
header += f" {desc}"
|
||||
header += f"\n {desc}"
|
||||
cmd_lines = []
|
||||
for cmd_name in plugins[plugin_name]:
|
||||
h = bot.registry.commands[cmd_name]
|
||||
@@ -120,7 +124,7 @@ async def cmd_help(bot, message):
|
||||
if h.help:
|
||||
line += f" -- {h.help}"
|
||||
cmd_lines.append(line)
|
||||
blocks.append(header + "\n" + "\n\n".join(cmd_lines))
|
||||
blocks.append(header + "\n\n" + "\n\n".join(cmd_lines))
|
||||
if blocks:
|
||||
url = await _paste(bot, "\n\n".join(blocks))
|
||||
if url:
|
||||
|
||||
Reference in New Issue
Block a user