diff options
author | Bambu <564972+bambu@users.noreply.github.com> | 2020-10-09 23:27:02 -0400 |
---|---|---|
committer | Bambu <564972+bambu@users.noreply.github.com> | 2020-10-09 23:27:02 -0400 |
commit | 19598b68106333d44a91aa6f62590232dff443ed (patch) | |
tree | 0c35e8fa0e07efc3828c238e4d7ea9fe4ddbe276 /cmd2 | |
parent | 52bbce0a938e3769d0814010245687c1473f7e5c (diff) | |
download | cmd2-git-19598b68106333d44a91aa6f62590232dff443ed.tar.gz |
Format multiline docstrings to match other help messages
Changed cmd2 do_cmd to dedent docstrings using `pydoc.getdoc`. This patch provides output for docstrings that look like using argparse or a single line docstring
Diffstat (limited to 'cmd2')
-rw-r--r-- | cmd2/cmd2.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index ea4e01de..12332f87 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,16 +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: + super().do_help(args.command) + + # If there's no help_func __doc__ then format and output it + elif func and func.__doc__: + 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""" |