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

55 lines
1.6 KiB
Markdown
Raw Normal View History

2020-07-30 16:20:24 -07:00
2019-11-11 18:30:46 -08:00
# jc
JC - JSON CLI output utility
* kellyjonbrazil@gmail.com
2022-01-19 10:31:46 -08:00
This package serializes the output of many standard unix command line tools
2022-01-19 19:19:25 -08:00
to dictionaries and lists of dictionaries.
2019-11-11 18:30:46 -08:00
2022-01-19 10:31:46 -08:00
For documentation on each parser, see the
2022-01-19 19:19:25 -08:00
[documentation site](https://kellyjonbrazil.github.io/jc/) or use
`jc.get_help('parser_module_name')`
2020-08-11 06:36:30 -07:00
2022-01-19 19:19:25 -08:00
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-19 19:24:37 -08:00
Available Functions (use `help(jc.lib)` for details):
2022-01-19 19:19:25 -08:00
2022-01-19 19:22:08 -08:00
parse(parser_module_name: str, data: str | iterable)
High-level API to easily access the parser. This API will find both
built-in parsers and local plugin parsers.
2022-01-19 19:19:25 -08:00
2022-01-19 19:22:08 -08:00
get_help(parser_module_name: str)
Convenience function to display the help screen for a parser using its
module name.
2022-01-19 19:19:25 -08:00
2022-01-19 19:22:08 -08:00
parser_mod_list()
Get a list of all available parser module names to be used in parse()
and get_help().
2022-01-19 19:19:25 -08:00
2022-01-19 19:22:08 -08:00
plugin_parser_mod_list()
Get a list of plugin parser module names. This list is a subset of
parser_mod_list().
2022-01-18 13:46:11 -08:00