File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 3434import inspect
3535import os
3636import pickle
37+ import pydoc
3738import re
3839import sys
3940import threading
@@ -3155,17 +3156,21 @@ def do_help(self, args: argparse.Namespace) -> None:
31553156 # Set end to blank so the help output matches how it looks when "command -h" is used
31563157 self .poutput (completer .format_help (tokens ), end = '' )
31573158
3159+ # If there is a help func delegate to do_help
3160+ elif help_func is not None :
3161+ super ().do_help (args .command )
3162+
3163+ # If there's no help_func __doc__ then format and output it
3164+ elif func is not None and func .__doc__ is not None :
3165+ self .poutput (pydoc .getdoc (func ))
3166+
31583167 # If there is no help information then print an error
3159- elif help_func is None and ( func is None or not func . __doc__ ) :
3168+ else :
31603169 err_msg = self .help_error .format (args .command )
31613170
31623171 # Set apply_style to False so help_error's style is not overridden
31633172 self .perror (err_msg , apply_style = False )
31643173
3165- # Otherwise delegate to cmd base class do_help()
3166- else :
3167- super ().do_help (args .command )
3168-
31693174 def _help_menu (self , verbose : bool = False ) -> None :
31703175 """Show a list of commands which help can be displayed for"""
31713176 cmds_cats , cmds_doc , cmds_undoc , help_topics = self ._build_command_info ()
Original file line number Diff line number Diff line change @@ -981,6 +981,16 @@ def do_edit(self, arg):
981981 def do_undoc (self , arg ):
982982 pass
983983
984+ def do_multiline_docstr (self , arg ):
985+ """
986+ This documentation
987+ is multiple lines
988+ and there are no
989+ tabs
990+ """
991+ pass
992+
993+
984994@pytest .fixture
985995def help_app ():
986996 app = HelpApp ()
@@ -1004,6 +1014,11 @@ def test_help_overridden_method(help_app):
10041014 expected = normalize ('This overrides the edit command and does nothing.' )
10051015 assert out == expected
10061016
1017+ def test_help_multiline_docstring (help_app ):
1018+ out , err = run_cmd (help_app , 'help multiline_docstr' )
1019+ expected = normalize ('This documentation\n is multiple lines\n and there are no\n tabs' )
1020+ assert out == expected
1021+
10071022
10081023class HelpCategoriesApp (cmd2 .Cmd ):
10091024 """Class for testing custom help_* methods which override docstring help."""
You can’t perform that action at this time.
0 commit comments