Skip to content

Commit 55b4e8e

Browse files
committed
Commands with categories will no longer show in the 'Undocumented commands' section
1 parent 6e54661 commit 55b4e8e

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

cmd2/cmd2.py

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,15 +2633,22 @@ def _help_menu(self, verbose: bool=False) -> None:
26332633

26342634
for command in visible_commands:
26352635
func = self.cmd_func(command)
2636-
if command in help_topics or func.__doc__:
2637-
if command in help_topics:
2638-
help_topics.remove(command)
2639-
if hasattr(func, HELP_CATEGORY):
2640-
category = getattr(func, HELP_CATEGORY)
2641-
cmds_cats.setdefault(category, [])
2642-
cmds_cats[category].append(command)
2643-
else:
2644-
cmds_doc.append(command)
2636+
has_help_func = False
2637+
2638+
if command in help_topics:
2639+
# Prevent the command from showing as both a command and help topic in the output
2640+
help_topics.remove(command)
2641+
2642+
# Non-argparse commands can have help_functions for their documentation
2643+
if not hasattr(func, 'argparser'):
2644+
has_help_func = True
2645+
2646+
if hasattr(func, HELP_CATEGORY):
2647+
category = getattr(func, HELP_CATEGORY)
2648+
cmds_cats.setdefault(category, [])
2649+
cmds_cats[category].append(command)
2650+
elif func.__doc__ or has_help_func:
2651+
cmds_doc.append(command)
26452652
else:
26462653
cmds_undoc.append(command)
26472654

@@ -2711,20 +2718,23 @@ def _print_topics(self, header: str, cmds: List[str], verbose: bool) -> None:
27112718
doc = cmd_func.__doc__
27122719

27132720
# Attempt to locate the first documentation block
2714-
doc_block = []
2715-
found_first = False
2716-
for doc_line in doc.splitlines():
2717-
stripped_line = doc_line.strip()
2718-
2719-
# Don't include :param type lines
2720-
if stripped_line.startswith(':'):
2721-
if found_first:
2721+
if not doc:
2722+
doc_block = ['']
2723+
else:
2724+
doc_block = []
2725+
found_first = False
2726+
for doc_line in doc.splitlines():
2727+
stripped_line = doc_line.strip()
2728+
2729+
# Don't include :param type lines
2730+
if stripped_line.startswith(':'):
2731+
if found_first:
2732+
break
2733+
elif stripped_line:
2734+
doc_block.append(stripped_line)
2735+
found_first = True
2736+
elif found_first:
27222737
break
2723-
elif stripped_line:
2724-
doc_block.append(stripped_line)
2725-
found_first = True
2726-
elif found_first:
2727-
break
27282738

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

0 commit comments

Comments
 (0)