1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

move parser doc printing to its own function

This commit is contained in:
Kelly Brazil
2021-04-09 09:12:41 -07:00
parent dd1ae6d9a7
commit c5d058490b

View File

@ -340,6 +340,27 @@ def helptext():
''' '''
return textwrap.dedent(helptext_string) 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(): def versiontext():
"""Return the version text""" """Return the version text"""
@ -485,19 +506,7 @@ def main():
sys.exit(0) sys.exit(0)
if help_me: if help_me:
# if no parser specified, print general help. If a parser is specified - e.g.: print(help_doc(sys.argv))
# 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())
sys.exit(0) sys.exit(0)
if version_info: if version_info: