Skip to content

Commit 0269c6c

Browse files
authored
Merge pull request #536 from python-cmd2/help_summary
Prevent :param and :return type lines from showing in help summaries
2 parents e5e8a79 + 850b234 commit 0269c6c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cmd2/cmd2.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,13 +2459,17 @@ def _print_topics(self, header: str, cmds: List[str], verbose: bool) -> None:
24592459
doc_block = []
24602460
found_first = False
24612461
for doc_line in doc.splitlines():
2462-
str(doc_line).strip()
2463-
if len(doc_line.strip()) > 0:
2464-
doc_block.append(doc_line.strip())
2465-
found_first = True
2466-
else:
2462+
stripped_line = doc_line.strip()
2463+
2464+
# Don't include :param type lines
2465+
if stripped_line.startswith(':'):
24672466
if found_first:
24682467
break
2468+
elif stripped_line:
2469+
doc_block.append(stripped_line)
2470+
found_first = True
2471+
elif found_first:
2472+
break
24692473

24702474
for doc_line in doc_block:
24712475
self.stdout.write('{: <{col_width}}{doc}\n'.format(command,

tests/test_cmd2.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ def test_base_help_verbose(base_app):
4646
expected = normalize(BASE_HELP_VERBOSE)
4747
assert out == expected
4848

49+
# Make sure :param type lines are filtered out of help summary
50+
help_doc = base_app.do_help.__func__.__doc__
51+
help_doc += "\n:param fake param"
52+
base_app.do_help.__func__.__doc__ = help_doc
53+
4954
out = run_cmd(base_app, 'help --verbose')
5055
assert out == expected
5156

0 commit comments

Comments
 (0)