From c5d058490beaa8f59875a8acfd7a400764768639 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 9 Apr 2021 09:12:41 -0700 Subject: [PATCH] move parser doc printing to its own function --- jc/cli.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/jc/cli.py b/jc/cli.py index 9d4467ee..18bc2a99 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -340,6 +340,27 @@ def helptext(): ''' return textwrap.dedent(helptext_string) +def help_doc(options): + """ + Returns the parser documentation if a parser is found in the arguments, otherwise + the general help text is returned. + """ + for arg in options: + parser_name = parser_shortname(arg) + + if parser_name in parsers: + # load parser module just in time so we don't need to load all modules + parser = parser_module(arg) + compatible = ', '.join(parser.info.compatible) + doc_text = f'''{parser.__doc__} +Compatibility: {compatible} + +Version {parser.info.version} by {parser.info.author} ({parser.info.author_email}) +''' + + return doc_text + + return helptext() def versiontext(): """Return the version text""" @@ -485,19 +506,7 @@ def main(): sys.exit(0) if help_me: - # if no parser specified, print general help. If a parser is specified - e.g.: - # jc -h arp - # then print the parser-specific help page (doc string) - for arg in sys.argv: - parser_name = parser_shortname(arg) - - if parser_name in parsers: - # load parser module just in time so we don't need to load all modules - parser = parser_module(arg) - print(parser.__doc__) - sys.exit(0) - - print(helptext()) + print(help_doc(sys.argv)) sys.exit(0) if version_info: