1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/docs/readme.md

106 lines
2.4 KiB
Markdown
Raw Normal View History

2022-01-25 17:07:47 -08:00
<a id="jc"></a>
2020-07-30 16:20:24 -07:00
2019-11-11 18:30:46 -08:00
# jc
2022-01-25 17:07:47 -08:00
2019-11-11 18:30:46 -08:00
JC - JSON CLI output utility
* kellyjonbrazil@gmail.com
2022-01-21 16:13:00 -08:00
This package converts the output of many standard unix command line tools
and file-types to dictionaries and lists of dictionaries.
2019-11-11 18:30:46 -08:00
2022-01-21 12:31:03 -08:00
## Interactive Documentation
2022-01-20 07:49:45 -08:00
2022-01-21 16:58:45 -08:00
>>> help('jc')
>>> help('jc.lib')
>>> help('jc.utils')
2022-02-07 06:29:17 -08:00
>>> help('jc.streaming')
>>> help('jc.parsers.universal')
2022-01-20 07:49:45 -08:00
>>> jc.get_help('parser_module_name')
2022-01-21 12:31:03 -08:00
## Online Documentation
2022-01-20 07:49:45 -08:00
2022-01-21 14:08:19 -08:00
### Latest
2022-01-21 12:33:23 -08:00
2022-01-20 07:49:45 -08:00
https://github.com/kellyjonbrazil/jc/tree/master/docs
2020-08-11 06:36:30 -07:00
2022-01-21 12:41:52 -08:00
### Specific Version
Replace `{{full_version_number}}` - e.g. `1.17.7`:
2022-01-21 12:33:23 -08:00
2022-01-21 12:35:48 -08:00
`https://github.com/kellyjonbrazil/jc/tree/v{{full_version_number}}/docs`
2022-01-21 12:31:03 -08:00
2022-01-21 12:39:22 -08:00
Specific versions can also be selected by tag in the branch dropdown menu.
2022-01-21 14:08:19 -08:00
## Usage Example
2019-11-11 18:30:46 -08:00
2022-01-18 13:40:09 -08:00
>>> import subprocess
>>> import jc
>>>
2022-01-19 10:31:46 -08:00
>>> cmd_output = subprocess.check_output(['dig', 'example.com'],
text=True)
2022-01-18 13:40:09 -08:00
>>> data = jc.parse('dig', cmd_output)
>>> data
2022-01-19 10:31:46 -08:00
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', ...}]
2022-01-18 13:40:09 -08:00
2022-01-19 10:31:46 -08:00
Alternatively, you can bypass the high-level API and call the parser
modules directly:
2022-01-18 13:40:09 -08:00
2021-09-10 14:27:50 -07:00
>>> import subprocess
>>> import jc.parsers.dig
>>>
2022-01-19 10:31:46 -08:00
>>> cmd_output = subprocess.check_output(['dig', 'example.com'],
text=True)
2021-09-10 14:27:50 -07:00
>>> data = jc.parsers.dig.parse(cmd_output)
>>> data
2022-01-19 10:31:46 -08:00
[{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', ...}]
2019-11-11 18:30:46 -08:00
2022-01-21 12:31:03 -08:00
## Available Functions
2022-03-02 10:15:01 -08:00
Use `help(jc.lib)` for details.
2022-03-02 15:24:18 -08:00
### parse
2022-01-19 19:19:25 -08:00
2022-03-02 15:24:18 -08:00
parse(
parser_module_name: str,
data: str | Iterable
) -> dict | list[dict] | Iterable[dict]
2022-03-02 10:15:01 -08:00
High-level API to easily access the parser. This API will find both
built-in parsers and local plugin parsers.
2022-03-02 15:24:18 -08:00
### parser_info
2022-01-19 19:19:25 -08:00
2022-01-26 18:05:00 -08:00
parser_info(parser_module_name: str) -> dict
2022-03-02 10:15:01 -08:00
Get the metadata for a particular parser.
2022-03-02 15:24:18 -08:00
### all_parser_info
2022-01-26 18:05:00 -08:00
all_parser_info() -> list[dict]
2022-03-02 10:15:01 -08:00
Get the metadata for all parsers.
2022-03-02 15:24:18 -08:00
### get_help
2022-01-26 18:05:00 -08:00
get_help(parser_module_name: str) -> None
2022-03-02 10:15:01 -08:00
Convenience function to display the help screen for a parser using
its module name.
2022-03-02 15:24:18 -08:00
### parser_mod_list
2022-01-19 19:19:25 -08:00
2022-01-26 18:05:00 -08:00
parser_mod_list() -> list
2022-03-02 10:15:01 -08:00
Get a list of all available parser module names to be used in
`parse()`, `parser_info()`, and `get_help()`.
2022-03-02 15:24:18 -08:00
### plugin_parser_mod_list
2022-01-19 19:19:25 -08:00
2022-01-26 18:05:00 -08:00
plugin_parser_mod_list() -> list
2022-03-02 10:15:01 -08:00
Get a list of plugin parser module names to be used in
`parse()`, `parser_info()`, and `get_help()`. This list is a subset of
`parser_mod_list()`.
2022-01-18 13:46:11 -08:00