mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-11 01:10:37 +02:00
add documentation argument to parser_info and all_parser_info
This commit is contained in:
@ -6,6 +6,7 @@ jc changelog
|
|||||||
- Add mpstat command parser tested on linux
|
- Add mpstat command parser tested on linux
|
||||||
- Add mpstat command streaming parser tested on linux
|
- Add mpstat command streaming parser tested on linux
|
||||||
- Add ASCII table parser
|
- Add ASCII table parser
|
||||||
|
- Add documentation option to parser_info() and all_parser_info()
|
||||||
|
|
||||||
20220305 v1.18.5
|
20220305 v1.18.5
|
||||||
- Fix date parser to ensure AM/PM period string is always uppercase
|
- Fix date parser to ensure AM/PM period string is always uppercase
|
||||||
|
@ -67,13 +67,16 @@ built-in parsers and local plugin parsers.
|
|||||||
|
|
||||||
### parser_info
|
### parser_info
|
||||||
|
|
||||||
parser_info(parser_module_name: str) -> dict
|
parser_info(
|
||||||
|
parser_module_name: str,
|
||||||
|
documentation: bool = False
|
||||||
|
) -> dict
|
||||||
|
|
||||||
Get the metadata for a particular parser.
|
Get the metadata for a particular parser.
|
||||||
|
|
||||||
### all_parser_info
|
### all_parser_info
|
||||||
|
|
||||||
all_parser_info() -> list[dict]
|
all_parser_info(documentation: bool = False) -> list[dict]
|
||||||
|
|
||||||
Get the metadata for all parsers.
|
Get the metadata for all parsers.
|
||||||
|
|
||||||
|
29
jc/lib.py
29
jc/lib.py
@ -1,7 +1,6 @@
|
|||||||
"""jc - JSON Convert
|
"""jc - JSON Convert
|
||||||
JC lib module
|
JC lib module
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -266,12 +265,18 @@ def streaming_parser_mod_list() -> List[str]:
|
|||||||
plist.append(_cliname_to_modname(p))
|
plist.append(_cliname_to_modname(p))
|
||||||
return plist
|
return plist
|
||||||
|
|
||||||
def parser_info(parser_mod_name: str) -> Dict:
|
def parser_info(parser_mod_name: str, documentation: bool = False) -> Dict:
|
||||||
"""
|
"""
|
||||||
Returns a dictionary that includes the module metadata.
|
Returns a dictionary that includes the parser module metadata.
|
||||||
|
|
||||||
This function will accept **module_name**, **cli-name**, and
|
Parameters:
|
||||||
**--argument-name** variants of the module name string.
|
|
||||||
|
parser_mod_name: (string) name of the parser module. This
|
||||||
|
function will accept module_name,
|
||||||
|
cli-name, and --argument-name
|
||||||
|
variants of the module name.
|
||||||
|
|
||||||
|
documentation: (boolean) include parser docstring if True
|
||||||
"""
|
"""
|
||||||
# ensure parser_mod_name is a true module name and not a cli name
|
# 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_name = _cliname_to_modname(parser_mod_name)
|
||||||
@ -291,13 +296,21 @@ def parser_info(parser_mod_name: str) -> Dict:
|
|||||||
if _modname_to_cliname(parser_mod_name) in local_parsers:
|
if _modname_to_cliname(parser_mod_name) in local_parsers:
|
||||||
info_dict['plugin'] = True
|
info_dict['plugin'] = True
|
||||||
|
|
||||||
|
if documentation:
|
||||||
|
info_dict['documentation'] = parser_mod.__doc__
|
||||||
|
|
||||||
return info_dict
|
return info_dict
|
||||||
|
|
||||||
def all_parser_info() -> List[Dict]:
|
def all_parser_info(documentation: bool = False) -> List[Dict]:
|
||||||
"""
|
"""
|
||||||
Returns a list of dictionaries that includes metadata for all modules.
|
Returns a list of dictionaries that includes metadata for all parser
|
||||||
|
modules.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
|
||||||
|
documentation: (boolean) include parser docstrings if True
|
||||||
"""
|
"""
|
||||||
return [parser_info(p) for p in parsers]
|
return [parser_info(p, documentation=documentation) for p in parsers]
|
||||||
|
|
||||||
def get_help(parser_mod_name: str) -> None:
|
def get_help(parser_mod_name: str) -> None:
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user