diff --git a/CHANGELOG b/CHANGELOG index 43d8c40a..3721cdb3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ jc changelog +20220118 v1.18.0 +- Add high-level parse API for built-in and plugin parsers + 20220106 v1.17.7 - Add stat command streaming parser tested on linux and macOS diff --git a/README.md b/README.md index a224d4a5..63b30071 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,10 @@ $ jc dig example.com | jq -r '.[].answer[].data' The `jc` parsers can also be used as python modules. In this case the output will be a python dictionary, or list of dictionaries, instead of JSON: ```python >>> import subprocess ->>> import jc.parsers.dig ->>> +>>> import jc +>>> >>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True) ->>> data = jc.parsers.dig.parse(cmd_output) +>>> data = jc.parse('dig', cmd_output) >>> >>> data [{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', 'ra'], 'query_num': 1, 'answer_num': @@ -290,9 +290,9 @@ Streaming parsers accept any iterable object and return a generator iterator obj To use the generator object in your code, simply loop through it or use the [next()](https://docs.python.org/3/library/functions.html#next) builtin function: ```python -import jc.parsers.ls_s +import jc -result = jc.parsers.ls_s.parse(ls_command_output.splitlines()) +result = jc.parse('ls_s', ls_command_output.splitlines()) for item in result: print(item["filename"]) ``` diff --git a/docs/readme.md b/docs/readme.md index 0f5aa6b5..437acbff 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -57,8 +57,22 @@ CLI Example: Module Example: - >>> import jc.parsers.dig + >>> import subprocess + >>> import jc >>> + >>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True) + >>> data = jc.parse('dig', cmd_output) + >>> + >>> data + [{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', 'ra'], 'query_num': 1, 'answer_num': + 1, 'authority_num': 0, 'additional_num': 1, 'opt_pseudosection': {'edns': {'version': 0, 'flags': [], 'udp': + 4096}}, 'question': {'name': 'example.com.', 'class': 'IN', 'type': 'A'}, 'answer': [{'name': 'example.com.', + 'class': 'IN', 'type': 'A', 'ttl': 29658, 'data': '93.184.216.34'}], 'query_time': 52, 'server': + '2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)', 'when': 'Fri Apr 16 16:13:00 PDT 2021', 'rcvd': 56, + 'when_epoch': 1618614780, 'when_epoch_utc': None}] + +Alternatively, you can bypass the high-level API and call the parser modules directly: + >>> import subprocess >>> import jc.parsers.dig >>> diff --git a/man/jc.1 b/man/jc.1 index 5589fc6a..6961c827 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -1,4 +1,4 @@ -.TH jc 1 2022-01-14 1.17.7 "JSON CLI output utility" +.TH jc 1 2022-01-18 1.18.0 "JSON CLI output utility" .SH NAME jc \- JSONifies the output of many CLI tools and file-types .SH SYNOPSIS diff --git a/templates/readme_template b/templates/readme_template index 18c6ec32..b77e03c7 100644 --- a/templates/readme_template +++ b/templates/readme_template @@ -32,10 +32,10 @@ $ jc dig example.com | jq -r '.[].answer[].data' The `jc` parsers can also be used as python modules. In this case the output will be a python dictionary, or list of dictionaries, instead of JSON: ```python >>> import subprocess ->>> import jc.parsers.dig ->>> +>>> import jc +>>> >>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True) ->>> data = jc.parsers.dig.parse(cmd_output) +>>> data = jc.parse('dig', cmd_output) >>> >>> data [{'id': 64612, 'opcode': 'QUERY', 'status': 'NOERROR', 'flags': ['qr', 'rd', 'ra'], 'query_num': 1, 'answer_num': @@ -206,9 +206,9 @@ Streaming parsers accept any iterable object and return a generator iterator obj To use the generator object in your code, simply loop through it or use the [next()](https://docs.python.org/3/library/functions.html#next) builtin function: ```python -import jc.parsers.ls_s +import jc -result = jc.parsers.ls_s.parse(ls_command_output.splitlines()) +result = jc.parse('ls_s', ls_command_output.splitlines()) for item in result: print(item["filename"]) ```