Skip to content

Commit cb956e5

Browse files
committed
Integrated rich-argparse.
1 parent 2433b2f commit cb956e5

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

cmd2/argparse_custom.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def my_completer(self, text, line, begidx, endidx, arg_tokens)
237237
IO,
238238
TYPE_CHECKING,
239239
Any,
240+
ClassVar,
240241
NoReturn,
241242
Optional,
242243
Protocol,
@@ -245,6 +246,10 @@ def my_completer(self, text, line, begidx, endidx, arg_tokens)
245246
runtime_checkable,
246247
)
247248

249+
from rich_argparse import (
250+
RawTextRichHelpFormatter,
251+
)
252+
248253
from . import (
249254
ansi,
250255
constants,
@@ -991,9 +996,25 @@ def _SubParsersAction_remove_parser(self: argparse._SubParsersAction, name: str)
991996
############################################################################################################
992997

993998

994-
class Cmd2HelpFormatter(argparse.RawTextHelpFormatter):
999+
class Cmd2HelpFormatter(RawTextRichHelpFormatter):
9951000
"""Custom help formatter to configure ordering of help text."""
9961001

1002+
# rich-argparse formats all group names with str.title().
1003+
# Override their formatter to do nothing.
1004+
group_name_formatter: ClassVar[Callable[[str], str]] = str
1005+
1006+
# Disable automatic highlighting in the help text.
1007+
highlights: ClassVar[list[str]] = []
1008+
1009+
# Disable markup rendering in usage, help, description, and epilog text.
1010+
# cmd2's built-in commands do not escape opening brackets in their help text
1011+
# and therefore rely on these settings being False. If you desire to use
1012+
# markup in your help text, inherit from a Cmd2 help formatter and override
1013+
# these settings in that child class.
1014+
usage_markup: ClassVar[bool] = False
1015+
help_markup: ClassVar[bool] = False
1016+
text_markup: ClassVar[bool] = False
1017+
9971018
def _format_usage(
9981019
self,
9991020
usage: Optional[str],

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies = [
3232
"gnureadline>=8; platform_system == 'Darwin'",
3333
"pyperclip>=1.8",
3434
"pyreadline3>=3.4; platform_system == 'Windows'",
35+
"rich-argparse>=1.7.1",
3536
"wcwidth>=0.2.10",
3637
]
3738

0 commit comments

Comments
 (0)