1
0
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:
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

@ -161,7 +161,7 @@ subset of `parser_mod_list()`.
### parser\_info ### parser\_info
```python ```python
def parser_info(parser_mod_name: str, def parser_info(parser_mod_name: Union[str, ModuleType],
documentation: bool = False) -> ParserInfoType documentation: bool = False) -> ParserInfoType
``` ```
@ -169,10 +169,11 @@ Returns a dictionary that includes the parser module metadata.
Parameters: Parameters:
parser_mod_name: (string) name of the parser module. This parser_mod_name: (string or name of the parser module. This
function will accept module_name, Module) function will accept module_name,
cli-name, and --argument-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 documentation: (boolean) include parser docstring if True
@ -203,11 +204,12 @@ Parameters:
### get\_help ### get\_help
```python ```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. Show help screen for the selected parser.
This function will accept **module_name**, **cli-name**, and 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.

View File

@ -453,22 +453,31 @@ def streaming_parser_mod_list(
return plist 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. Returns a dictionary that includes the parser module metadata.
Parameters: Parameters:
parser_mod_name: (string) name of the parser module. This parser_mod_name: (string or name of the parser module. This
function will accept module_name, Module) function will accept module_name,
cli-name, and --argument-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 documentation: (boolean) include parser docstring if True
""" """
# ensure parser_mod_name is a true module name and not a cli name if isinstance(parser_mod_name, ModuleType):
parser_mod_name = _cliname_to_modname(parser_mod_name) parser_mod = parser_mod_name
parser_mod = _get_parser(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 = {} info_dict: ParserInfoType = {}
if hasattr(parser_mod, 'info'): if hasattr(parser_mod, 'info'):
@ -525,11 +534,17 @@ def all_parser_info(
return p_info_list 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. Show help screen for the selected parser.
This function will accept **module_name**, **cli-name**, and 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)

View File

@ -1,4 +1,4 @@
.TH jc 1 2022-10-25 1.22.2 "JSON Convert" .TH jc 1 2022-10-28 1.22.2 "JSON Convert"
.SH NAME .SH NAME
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types, and strings \fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types, and strings
.SH SYNOPSIS .SH SYNOPSIS