1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-11 01:10:37 +02:00

allow parser_info and get_help to use module objects as input

This commit is contained in:
Kelly Brazil
2022-10-28 10:36:54 -07:00
parent 2b621ab68e
commit 747d12224f
3 changed files with 34 additions and 17 deletions

View File

@ -453,22 +453,31 @@ def streaming_parser_mod_list(
return plist
def parser_info(parser_mod_name: str, documentation: bool = False) -> ParserInfoType:
def parser_info(
parser_mod_name: Union[str, ModuleType],
documentation: bool = False
) -> ParserInfoType:
"""
Returns a dictionary that includes the parser module metadata.
Parameters:
parser_mod_name: (string) name of the parser module. This
function will accept module_name,
parser_mod_name: (string or name of the parser module. This
Module) function will accept module_name,
cli-name, and --argument-name
variants of the module name.
variants of the module name as well
as a parser module object.
documentation: (boolean) include parser docstring if True
"""
# ensure parser_mod_name is a true module name and not a cli name
parser_mod_name = _cliname_to_modname(parser_mod_name)
parser_mod = _get_parser(parser_mod_name)
if isinstance(parser_mod_name, ModuleType):
parser_mod = parser_mod_name
parser_mod_name = parser_mod.__name__.split('.')[-1]
else:
# ensure parser_mod_name is a true module name and not a cli name
parser_mod_name = _cliname_to_modname(parser_mod_name)
parser_mod = _get_parser(parser_mod_name)
info_dict: ParserInfoType = {}
if hasattr(parser_mod, 'info'):
@ -525,11 +534,17 @@ def all_parser_info(
return p_info_list
def get_help(parser_mod_name: str) -> None:
def get_help(parser_mod_name: Union[str, ModuleType]) -> None:
"""
Show help screen for the selected parser.
This function will accept **module_name**, **cli-name**, and
**--argument-name** variants of the module name string.
**--argument-name** variants of the module name string as well as a
parser module object.
"""
help(_get_parser(parser_mod_name))
if isinstance(parser_mod_name, ModuleType):
jc_parser = parser_mod_name
else:
jc_parser = _get_parser(parser_mod_name)
help(jc_parser)