From 983ef66ea376701ad615fc9cb18098471219eaf9 Mon Sep 17 00:00:00 2001 From: Chris Tomkins-Tinch Date: Wed, 29 Jun 2016 20:29:07 -0400 Subject: [PATCH] hide "Undocumented" for subparser help on RTD (#385) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adjust documentation for RTD and display Now, the parser docstring is used as the help string for a given subparser. This ensures ReadTheDocs displays a string rather than “Undocumented” * readthedocs test * give a blank string for subparser help if the parser function docstring is null so sphinx-argparse doesn't render "Undocumented" give a blank string for subparser help if the parser function docstring is null so sphinx-argparse doesn't render "Undocumented" --- util/cmd.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/util/cmd.py b/util/cmd.py index c965f4ce3..6a289d3df 100644 --- a/util/cmd.py +++ b/util/cmd.py @@ -156,9 +156,14 @@ def make_parser(commands, description): parser = argparse.ArgumentParser(description=description, usage='%(prog)s subcommand', add_help=False) parser.add_argument('--help', '-h', action=_HelpAction, help=argparse.SUPPRESS) parser.add_argument('--version', '-V', action='version', version=__version__, help=argparse.SUPPRESS) - subparsers = parser.add_subparsers(title='subcommands', dest='command') + subparsers = parser.add_subparsers(title='subcommands', dest='command', metavar='\033[F') # \033[F moves cursor up for cmd_name, cmd_parser in commands: - p = subparsers.add_parser(cmd_name) + help_str = cmd_parser.__doc__ if cmd_parser.__doc__ and len(cmd_parser.__doc__) else None + # give a blank string for help if the parser docstring is null + # so sphinx-argparse doesnt't render "Undocumented" + if (not help_str) and os.environ.get('READTHEDOCS') or 'sphinx' in sys.modules: + help_str = " " + p = subparsers.add_parser(cmd_name, help=help_str) cmd_parser(p) return parser