mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-09 01:05:53 +02:00
allow parser_info and get_help to use module objects as input
This commit is contained in:
14
docs/lib.md
14
docs/lib.md
@ -161,7 +161,7 @@ subset of `parser_mod_list()`.
|
||||
### parser\_info
|
||||
|
||||
```python
|
||||
def parser_info(parser_mod_name: str,
|
||||
def parser_info(parser_mod_name: Union[str, ModuleType],
|
||||
documentation: bool = False) -> ParserInfoType
|
||||
```
|
||||
|
||||
@ -169,10 +169,11 @@ 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
|
||||
|
||||
@ -203,11 +204,12 @@ Parameters:
|
||||
### get\_help
|
||||
|
||||
```python
|
||||
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.
|
||||
|
||||
|
35
jc/lib.py
35
jc/lib.py
@ -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)
|
||||
|
Reference in New Issue
Block a user