Skip to content

Commit 357b539

Browse files
committed
Switch to argparse.RawDescriptionHelpFormatter as the help formatter.
Fixes #42 Signed-off-by: Pedro Algarvio <[email protected]>
1 parent bc36c28 commit 357b539

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

changelog/42.added.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Switch to `RawDescriptionHelpFormatter` as the formatter class. This will help to include properly indented examples.

src/ptscripts/parser.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ def __new__(cls) -> Parser:
489489
description="Python Tools Scripts",
490490
epilog="These tools are discovered under `<repo-root>/tools`.",
491491
allow_abbrev=False,
492+
formatter_class=argparse.RawDescriptionHelpFormatter,
492493
)
493494
instance.parser.add_argument("--version", action="version", version=__version__)
494495
log_group = instance.parser.add_argument_group("Logging")
@@ -700,6 +701,7 @@ def __init__(
700701
name.replace("_", "-"),
701702
help=help,
702703
description=description,
704+
formatter_class=argparse.RawDescriptionHelpFormatter,
703705
)
704706
self.subparsers = self.parser.add_subparsers(
705707
title="Commands",
@@ -743,7 +745,12 @@ def command( # noqa: ANN201,C901,PLR0912,PLR0915
743745
description = inspect.getdoc(func)
744746
if help is None and description is not None:
745747
help = description.splitlines()[0]
746-
command = self.subparsers.add_parser(name=name, help=help, description=description)
748+
command = self.subparsers.add_parser(
749+
name=name,
750+
help=help,
751+
description=description,
752+
formatter_class=argparse.RawDescriptionHelpFormatter,
753+
)
747754

748755
signature = inspect.signature(func)
749756

0 commit comments

Comments
 (0)