summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2020-11-11 21:17:23 -0500
committerGitHub <noreply@github.com>2020-11-11 21:17:23 -0500
commitaac467e6eb2557b15170919446b2d9cc8fffabdc (patch)
tree60a304ac442574202ff08406cf0a432afe2e393e /cmd2/cmd2.py
parent887bda494c53d6f7457bb70fbbd20b5daf09125f (diff)
parent86d0e9c788ae88738e37242ad8d4c1047b443266 (diff)
downloadcmd2-git-aac467e6eb2557b15170919446b2d9cc8fffabdc.tar.gz
Merge pull request #1007 from bambu/docstr_fmt
Format multiline doc strings to match style of other help messages
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 8e23eca0..c8f5a9bd 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -34,6 +34,7 @@ import glob
import inspect
import os
import pickle
+import pydoc
import re
import sys
import threading
@@ -3155,17 +3156,21 @@ class Cmd(cmd.Cmd):
# 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()