Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import inspect
import os
import pickle
import pydoc
import re
import sys
import threading
Expand Down Expand Up @@ -3155,17 +3156,21 @@ def do_help(self, args: argparse.Namespace) -> None:
# Set end to blank so the help output matches how it looks when "command -h" is used
self.poutput(completer.format_help(tokens), end='')

# If there is a help func delegate to do_help
elif help_func is not None:
super().do_help(args.command)

# If there's no help_func __doc__ then format and output it
elif func is not None and func.__doc__ is not None:
self.poutput(pydoc.getdoc(func))

# If there is no help information then print an error
elif help_func is None and (func is None or not func.__doc__):
else:
err_msg = self.help_error.format(args.command)

# Set apply_style to False so help_error's style is not overridden
self.perror(err_msg, apply_style=False)

# Otherwise delegate to cmd base class do_help()
else:
super().do_help(args.command)

def _help_menu(self, verbose: bool = False) -> None:
"""Show a list of commands which help can be displayed for"""
cmds_cats, cmds_doc, cmds_undoc, help_topics = self._build_command_info()
Expand Down
15 changes: 15 additions & 0 deletions tests/test_cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,16 @@ def do_edit(self, arg):
def do_undoc(self, arg):
pass

def do_multiline_docstr(self, arg):
"""
This documentation
is multiple lines
and there are no
tabs
"""
pass


@pytest.fixture
def help_app():
app = HelpApp()
Expand All @@ -1004,6 +1014,11 @@ def test_help_overridden_method(help_app):
expected = normalize('This overrides the edit command and does nothing.')
assert out == expected

def test_help_multiline_docstring(help_app):
out, err = run_cmd(help_app, 'help multiline_docstr')
expected = normalize('This documentation\nis multiple lines\nand there are no\ntabs')
assert out == expected


class HelpCategoriesApp(cmd2.Cmd):
"""Class for testing custom help_* methods which override docstring help."""
Expand Down