Skip to content

Commit 5667a91

Browse files
committed
[rich_utils] added Paragraph Help Formatters based on rich_argparse classes
1 parent 715b57d commit 5667a91

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

cmd2/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
from .rich_utils import (
4848
ArgumentDefaultsCmd2HelpFormatter,
4949
Cmd2HelpFormatter,
50+
ExtendedParagraphCmd2HelpFormatter,
5051
MetavarTypeCmd2HelpFormatter,
52+
ParagraphCmd2HelpFormatter,
5153
RawDescriptionCmd2HelpFormatter,
5254
RawTextCmd2HelpFormatter,
5355
TextGroup,
@@ -101,7 +103,9 @@
101103
"ArgumentDefaultsCmd2HelpFormatter",
102104
"Cmd2HelpFormatter",
103105
"get_theme",
106+
"ExtendedParagraphCmd2HelpFormatter",
104107
"MetavarTypeCmd2HelpFormatter",
108+
"ParagraphCmd2HelpFormatter",
105109
"RawDescriptionCmd2HelpFormatter",
106110
"RawTextCmd2HelpFormatter",
107111
"set_theme",

cmd2/rich_utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
RawTextRichHelpFormatter,
4545
RichHelpFormatter,
4646
)
47+
from rich_argparse.contrib import ExtendedParagraphRichHelpFormatter, ParagraphRichHelpFormatter
4748

4849
from . import constants
4950
from .styles import (
@@ -269,6 +270,24 @@ class MetavarTypeCmd2HelpFormatter(
269270
""" # noqa: D205
270271

271272

273+
class ParagraphCmd2HelpFormatter(
274+
ParagraphRichHelpFormatter,
275+
Cmd2HelpFormatter,
276+
):
277+
r"""Rich help message formatter which retains paragraph separation with spacing
278+
using `\\n\\n`.
279+
""" # noqa: D205
280+
281+
282+
class ExtendedParagraphCmd2HelpFormatter(
283+
ExtendedParagraphRichHelpFormatter,
284+
Cmd2HelpFormatter,
285+
):
286+
r"""Cmd2 help message formatter which retains paragraph separation without
287+
spacing using `\\n\\n` and paragraph spacing using `\\n\\n\\n`.
288+
""" # noqa: D205
289+
290+
272291
class TextGroup:
273292
"""A block of text which is formatted like an argparse argument group, including a title.
274293

docs/features/argument_processing.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ This command cannot generate tags with no content, like <br/>
206206

207207
### Argparse HelpFormatter classes
208208

209-
`cmd2` has 5 different Argparse HelpFormatter classes, all of which are based on the
209+
`cmd2` has 7 different Argparse HelpFormatter classes, all of which are based on the
210210
`RichHelpFormatter` class from [rich-argparse](https://github.com/hamdanal/rich-argparse). The
211211
benefit is that your `cmd2` applications now have more aesthetically pleasing help which includes
212212
color to make it quicker and easier to visually parse help text. This works for all supported
@@ -215,8 +215,12 @@ versions of Python.
215215
- [Cmd2HelpFormatter][cmd2.argparse_utils.Cmd2HelpFormatter] - default help formatter class
216216
- [ArgumentDefaultsCmd2HelpFormatter][cmd2.argparse_utils.ArgumentDefaultsCmd2HelpFormatter] - adds
217217
default values to argument help
218+
- [ParagraphCmd2HelpFormatter][cmd2.argparse_utils.ParagraphCmd2HelpFormatter] - retains paragraph
219+
separation with spacing using `\\n\\n`
218220
- [MetavarTypeCmd2HelpFormatter][cmd2.argparse_utils.MetavarTypeCmd2HelpFormatter] - uses the
219221
argument 'type' as the default metavar value (instead of the argument 'dest')
222+
- [ExtendedParagraphCmd2HelpFormatter][cmd2.argparse_utils.ExtendedParagraphCmd2HelpFormatter] - retains
223+
paragraph separation without spacing using `\\n\\n` and paragraph spacing using `\\n\\n\\n`
220224
- [RawDescriptionCmd2HelpFormatter][cmd2.argparse_utils.RawDescriptionCmd2HelpFormatter] - retains
221225
any formatting in descriptions and epilogs
222226
- [RawTextCmd2HelpFormatter][cmd2.argparse_utils.RawTextCmd2HelpFormatter] - retains formatting of

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies = [
3333
"prompt-toolkit>=3.0.52",
3434
"pyperclip>=1.8.2",
3535
"rich>=15.0.0",
36-
"rich-argparse>=1.7.2",
36+
"rich-argparse>=1.8.0",
3737
"typing-extensions; python_version == '3.10'",
3838
]
3939

0 commit comments

Comments
 (0)