Skip to content

Commit 4616b09

Browse files
committed
Don't use parser description in verbose help output since it may be a Rich object.
1 parent bfca4e9 commit 4616b09

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

cmd2/cmd2.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ def get(self, command_method: CommandFunc) -> Optional[argparse.ArgumentParser]:
273273
_set_parser_prog(parser, command)
274274

275275
# If the description has not been set, then use the method docstring if one exists
276-
if parser.description is None and hasattr(command_method, '__wrapped__') and command_method.__wrapped__.__doc__:
277-
parser.description = strip_doc_annotations(command_method.__wrapped__.__doc__)
276+
if parser.description is None and command_method.__doc__:
277+
parser.description = strip_doc_annotations(command_method.__doc__)
278278

279279
self._parsers[full_method_name] = parser
280280

@@ -3753,12 +3753,8 @@ def _print_topics(self, header: str, cmds: list[str], verbose: bool) -> None:
37533753

37543754
doc: Optional[str]
37553755

3756-
# If this is an argparse command, use its description.
3757-
if (cmd_parser := self._command_parsers.get(cmd_func)) is not None:
3758-
doc = cmd_parser.description
3759-
37603756
# Non-argparse commands can have help_functions for their documentation
3761-
elif command in topics:
3757+
if command in topics:
37623758
help_func = getattr(self, constants.HELP_FUNC_PREFIX + command)
37633759
result = io.StringIO()
37643760

tests/test_cmd2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,9 +1256,10 @@ def test_help_multiline_docstring(help_app):
12561256
assert help_app.last_result is True
12571257

12581258

1259-
def test_help_verbose_uses_parser_description(help_app: HelpApp):
1259+
def test_help_verbose_uses_parser_docstring(help_app: HelpApp):
12601260
out, err = run_cmd(help_app, 'help --verbose')
1261-
verify_help_text(help_app, out, verbose_strings=[help_app.parser_cmd_parser.description])
1261+
expected_verbose = utils.strip_doc_annotations(help_app.do_parser_cmd.__doc__)
1262+
verify_help_text(help_app, out, verbose_strings=[expected_verbose])
12621263

12631264

12641265
class HelpCategoriesApp(cmd2.Cmd):

0 commit comments

Comments
 (0)