File tree 2 files changed +25
-5
lines changed 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 34
34
import inspect
35
35
import os
36
36
import pickle
37
+ import pydoc
37
38
import re
38
39
import sys
39
40
import threading
@@ -3155,17 +3156,21 @@ def do_help(self, args: argparse.Namespace) -> None:
3155
3156
# Set end to blank so the help output matches how it looks when "command -h" is used
3156
3157
self .poutput (completer .format_help (tokens ), end = '' )
3157
3158
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
+
3158
3167
# 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 :
3160
3169
err_msg = self .help_error .format (args .command )
3161
3170
3162
3171
# Set apply_style to False so help_error's style is not overridden
3163
3172
self .perror (err_msg , apply_style = False )
3164
3173
3165
- # Otherwise delegate to cmd base class do_help()
3166
- else :
3167
- super ().do_help (args .command )
3168
-
3169
3174
def _help_menu (self , verbose : bool = False ) -> None :
3170
3175
"""Show a list of commands which help can be displayed for"""
3171
3176
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):
981
981
def do_undoc (self , arg ):
982
982
pass
983
983
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
+
984
994
@pytest .fixture
985
995
def help_app ():
986
996
app = HelpApp ()
@@ -1004,6 +1014,11 @@ def test_help_overridden_method(help_app):
1004
1014
expected = normalize ('This overrides the edit command and does nothing.' )
1005
1015
assert out == expected
1006
1016
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
+
1007
1022
1008
1023
class HelpCategoriesApp (cmd2 .Cmd ):
1009
1024
"""Class for testing custom help_* methods which override docstring help."""
You can’t perform that action at this time.
0 commit comments