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
|
### 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.
|
||||||
|
|
||||||
|
35
jc/lib.py
35
jc/lib.py
@ -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)
|
||||||
|
2
man/jc.1
2
man/jc.1
@ -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
|
||||||
|
Reference in New Issue
Block a user