mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-15 01:24:29 +02:00
Merge branch 'dev' of https://github.com/kellyjonbrazil/jc into dev
This commit is contained in:
42
README.md
42
README.md
@ -292,7 +292,9 @@ option.
|
||||
|
||||
### Exit Codes
|
||||
Any fatal errors within `jc` will generate an exit code of `100`, otherwise the
|
||||
exit code will be `0`. When using the "magic" syntax (e.g. `jc ifconfig eth0`),
|
||||
exit code will be `0`.
|
||||
|
||||
When using the "magic" syntax (e.g. `jc ifconfig eth0`),
|
||||
`jc` will store the exit code of the program being parsed and add it to the `jc`
|
||||
exit code. This way it is easier to determine if an error was from the parsed
|
||||
program or `jc`.
|
||||
@ -306,6 +308,44 @@ Consider the following examples using `ifconfig`:
|
||||
| `0` | `100` | `100` | Error in `jc` |
|
||||
| `1` | `100` | `101` | Error in both `ifconfig` and `jc` |
|
||||
|
||||
When using the "magic" syntax you can also retrieve the exit code of the called
|
||||
program by using the `--meta-out` or `-M` option. This will append a `_jc_meta`
|
||||
object to the output that will include the magic command information, including
|
||||
the exit code.
|
||||
|
||||
Here is an example with `ping`:
|
||||
```bash
|
||||
$ jc --meta-out -p ping -c2 192.168.1.252
|
||||
{
|
||||
"destination_ip": "192.168.1.252",
|
||||
"data_bytes": 56,
|
||||
"pattern": null,
|
||||
"destination": "192.168.1.252",
|
||||
"packets_transmitted": 2,
|
||||
"packets_received": 0,
|
||||
"packet_loss_percent": 100.0,
|
||||
"duplicates": 0,
|
||||
"responses": [
|
||||
{
|
||||
"type": "timeout",
|
||||
"icmp_seq": 0,
|
||||
"duplicate": false
|
||||
}
|
||||
],
|
||||
"_jc_meta": {
|
||||
"parser": "ping",
|
||||
"timestamp": 1661357115.27949,
|
||||
"magic_command": [
|
||||
"ping",
|
||||
"-c2",
|
||||
"192.168.1.252"
|
||||
],
|
||||
"magic_command_exit": 2
|
||||
}
|
||||
}
|
||||
$ echo $?
|
||||
2
|
||||
```
|
||||
|
||||
### Setting Custom Colors via Environment Variable
|
||||
You can specify custom colors via the `JC_COLORS` environment variable. The
|
||||
|
17
docs/lib.md
17
docs/lib.md
@ -34,11 +34,22 @@ Parse the string data using the supplied parser module.
|
||||
This function provides a high-level API to simplify parser use. This
|
||||
function will call built-in parsers and custom plugin parsers.
|
||||
|
||||
Example:
|
||||
Example (standard parsers):
|
||||
|
||||
>>> import jc
|
||||
>>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022')
|
||||
{'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...}
|
||||
>>> date_obj = jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022')
|
||||
>>> print(f'The year is: {date_obj["year"]}')
|
||||
The year is: 2022
|
||||
|
||||
Example (streaming parsers):
|
||||
|
||||
>>> import jc
|
||||
>>> ping_gen = jc.parse('ping_s', ping_output.splitlines())
|
||||
>>> for item in ping_gen:
|
||||
>>> print(f'Response time: {item["time_ms"]} ms')
|
||||
Response time: 102 ms
|
||||
Response time: 109 ms
|
||||
...
|
||||
|
||||
To get a list of available parser module names, use `parser_mod_list()`.
|
||||
|
||||
|
@ -11,12 +11,17 @@ and file-types to dictionaries and lists of dictionaries.
|
||||
|
||||
## Interactive Documentation
|
||||
|
||||
Using `jc` in your python programs:
|
||||
|
||||
>>> help('jc')
|
||||
>>> help('jc.lib')
|
||||
>>> jc.get_help('parser_module_name')
|
||||
|
||||
Developing `jc` parsers:
|
||||
|
||||
>>> help('jc.utils')
|
||||
>>> help('jc.streaming')
|
||||
>>> help('jc.parsers.universal')
|
||||
>>> jc.get_help('parser_module_name')
|
||||
|
||||
## Online Documentation
|
||||
|
||||
|
@ -7,12 +7,17 @@ and file-types to dictionaries and lists of dictionaries.
|
||||
|
||||
## Interactive Documentation
|
||||
|
||||
Using `jc` in your python programs:
|
||||
|
||||
>>> help('jc')
|
||||
>>> help('jc.lib')
|
||||
>>> jc.get_help('parser_module_name')
|
||||
|
||||
Developing `jc` parsers:
|
||||
|
||||
>>> help('jc.utils')
|
||||
>>> help('jc.streaming')
|
||||
>>> help('jc.parsers.universal')
|
||||
>>> jc.get_help('parser_module_name')
|
||||
|
||||
## Online Documentation
|
||||
|
||||
|
17
jc/lib.py
17
jc/lib.py
@ -197,11 +197,22 @@ def parse(
|
||||
This function provides a high-level API to simplify parser use. This
|
||||
function will call built-in parsers and custom plugin parsers.
|
||||
|
||||
Example:
|
||||
Example (standard parsers):
|
||||
|
||||
>>> import jc
|
||||
>>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022')
|
||||
{'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...}
|
||||
>>> date_obj = jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022')
|
||||
>>> print(f'The year is: {date_obj["year"]}')
|
||||
The year is: 2022
|
||||
|
||||
Example (streaming parsers):
|
||||
|
||||
>>> import jc
|
||||
>>> ping_gen = jc.parse('ping_s', ping_output.splitlines())
|
||||
>>> for item in ping_gen:
|
||||
>>> print(f'Response time: {item["time_ms"]} ms')
|
||||
Response time: 102 ms
|
||||
Response time: 109 ms
|
||||
...
|
||||
|
||||
To get a list of available parser module names, use `parser_mod_list()`.
|
||||
|
||||
|
47
man/jc.1
47
man/jc.1
@ -1,4 +1,4 @@
|
||||
.TH jc 1 2022-08-21 1.21.0 "JSON Convert"
|
||||
.TH jc 1 2022-08-24 1.21.0 "JSON Convert"
|
||||
.SH NAME
|
||||
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools and file-types
|
||||
.SH SYNOPSIS
|
||||
@ -682,7 +682,9 @@ Generate Bash shell completion script
|
||||
Generate Zsh shell completion script
|
||||
|
||||
.SH EXIT CODES
|
||||
Any fatal errors within \fBjc\fP will generate an exit code of \fB100\fP, otherwise the exit code will be \fB0\fP. When using the "Magic" syntax (e.g. \fBjc ifconfig eth0\fP), \fBjc\fP will store the exit code of the program being parsed and add it to the \fBjc\fP exit code. This way it is easier to determine if an error was from the parsed program or \fBjc\fP.
|
||||
Any fatal errors within \fBjc\fP will generate an exit code of \fB100\fP, otherwise the exit code will be \fB0\fP.
|
||||
|
||||
When using the "magic" syntax (e.g. \fBjc ifconfig eth0\fP), \fBjc\fP will store the exit code of the program being parsed and add it to the \fBjc\fP exit code. This way it is easier to determine if an error was from the parsed program or \fBjc\fP.
|
||||
|
||||
Consider the following examples using \fBifconfig\fP:
|
||||
|
||||
@ -696,6 +698,47 @@ ifconfig exit code = \fB0\fP, jc exit code = \fB100\fP, combined exit code = \fB
|
||||
ifconfig exit code = \fB1\fP, jc exit code = \fB100\fP, combined exit code = \fB101\fP (error in both ifconfig and jc)
|
||||
.RE
|
||||
|
||||
When using the "magic" syntax you can also retrieve the exit code of the called
|
||||
program by using the \fB--meta-out\fP or \fB-M\fP option. This will append a \fB_jc_meta\fP
|
||||
object to the output that will include the magic command information, including
|
||||
the exit code.
|
||||
|
||||
Here is an example with \fBping\fP:
|
||||
.RS
|
||||
.nf
|
||||
$ jc --meta-out -p ping -c2 192.168.1.252
|
||||
{
|
||||
"destination_ip": "192.168.1.252",
|
||||
"data_bytes": 56,
|
||||
"pattern": null,
|
||||
"destination": "192.168.1.252",
|
||||
"packets_transmitted": 2,
|
||||
"packets_received": 0,
|
||||
"packet_loss_percent": 100.0,
|
||||
"duplicates": 0,
|
||||
"responses": [
|
||||
{
|
||||
"type": "timeout",
|
||||
"icmp_seq": 0,
|
||||
"duplicate": false
|
||||
}
|
||||
],
|
||||
"_jc_meta": {
|
||||
"parser": "ping",
|
||||
"timestamp": 1661357115.27949,
|
||||
"magic_command": [
|
||||
"ping",
|
||||
"-c2",
|
||||
"192.168.1.252"
|
||||
],
|
||||
"magic_command_exit": 2
|
||||
}
|
||||
}
|
||||
$ echo $?
|
||||
2
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.SH ENVIRONMENT
|
||||
|
||||
\fBCustom Colors\fP
|
||||
|
@ -87,7 +87,9 @@ Generate Bash shell completion script
|
||||
Generate Zsh shell completion script
|
||||
|
||||
.SH EXIT CODES
|
||||
Any fatal errors within \fBjc\fP will generate an exit code of \fB100\fP, otherwise the exit code will be \fB0\fP. When using the "Magic" syntax (e.g. \fBjc ifconfig eth0\fP), \fBjc\fP will store the exit code of the program being parsed and add it to the \fBjc\fP exit code. This way it is easier to determine if an error was from the parsed program or \fBjc\fP.
|
||||
Any fatal errors within \fBjc\fP will generate an exit code of \fB100\fP, otherwise the exit code will be \fB0\fP.
|
||||
|
||||
When using the "magic" syntax (e.g. \fBjc ifconfig eth0\fP), \fBjc\fP will store the exit code of the program being parsed and add it to the \fBjc\fP exit code. This way it is easier to determine if an error was from the parsed program or \fBjc\fP.
|
||||
|
||||
Consider the following examples using \fBifconfig\fP:
|
||||
|
||||
@ -101,6 +103,47 @@ ifconfig exit code = \fB0\fP, jc exit code = \fB100\fP, combined exit code = \fB
|
||||
ifconfig exit code = \fB1\fP, jc exit code = \fB100\fP, combined exit code = \fB101\fP (error in both ifconfig and jc)
|
||||
.RE
|
||||
|
||||
When using the "magic" syntax you can also retrieve the exit code of the called
|
||||
program by using the \fB--meta-out\fP or \fB-M\fP option. This will append a \fB_jc_meta\fP
|
||||
object to the output that will include the magic command information, including
|
||||
the exit code.
|
||||
|
||||
Here is an example with \fBping\fP:
|
||||
.RS
|
||||
.nf
|
||||
$ jc --meta-out -p ping -c2 192.168.1.252
|
||||
{
|
||||
"destination_ip": "192.168.1.252",
|
||||
"data_bytes": 56,
|
||||
"pattern": null,
|
||||
"destination": "192.168.1.252",
|
||||
"packets_transmitted": 2,
|
||||
"packets_received": 0,
|
||||
"packet_loss_percent": 100.0,
|
||||
"duplicates": 0,
|
||||
"responses": [
|
||||
{
|
||||
"type": "timeout",
|
||||
"icmp_seq": 0,
|
||||
"duplicate": false
|
||||
}
|
||||
],
|
||||
"_jc_meta": {
|
||||
"parser": "ping",
|
||||
"timestamp": 1661357115.27949,
|
||||
"magic_command": [
|
||||
"ping",
|
||||
"-c2",
|
||||
"192.168.1.252"
|
||||
],
|
||||
"magic_command_exit": 2
|
||||
}
|
||||
}
|
||||
$ echo $?
|
||||
2
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.SH ENVIRONMENT
|
||||
|
||||
\fBCustom Colors\fP
|
||||
|
@ -173,7 +173,9 @@ option.
|
||||
|
||||
### Exit Codes
|
||||
Any fatal errors within `jc` will generate an exit code of `100`, otherwise the
|
||||
exit code will be `0`. When using the "magic" syntax (e.g. `jc ifconfig eth0`),
|
||||
exit code will be `0`.
|
||||
|
||||
When using the "magic" syntax (e.g. `jc ifconfig eth0`),
|
||||
`jc` will store the exit code of the program being parsed and add it to the `jc`
|
||||
exit code. This way it is easier to determine if an error was from the parsed
|
||||
program or `jc`.
|
||||
@ -187,6 +189,44 @@ Consider the following examples using `ifconfig`:
|
||||
| `0` | `100` | `100` | Error in `jc` |
|
||||
| `1` | `100` | `101` | Error in both `ifconfig` and `jc` |
|
||||
|
||||
When using the "magic" syntax you can also retrieve the exit code of the called
|
||||
program by using the `--meta-out` or `-M` option. This will append a `_jc_meta`
|
||||
object to the output that will include the magic command information, including
|
||||
the exit code.
|
||||
|
||||
Here is an example with `ping`:
|
||||
```bash
|
||||
$ jc --meta-out -p ping -c2 192.168.1.252
|
||||
{
|
||||
"destination_ip": "192.168.1.252",
|
||||
"data_bytes": 56,
|
||||
"pattern": null,
|
||||
"destination": "192.168.1.252",
|
||||
"packets_transmitted": 2,
|
||||
"packets_received": 0,
|
||||
"packet_loss_percent": 100.0,
|
||||
"duplicates": 0,
|
||||
"responses": [
|
||||
{
|
||||
"type": "timeout",
|
||||
"icmp_seq": 0,
|
||||
"duplicate": false
|
||||
}
|
||||
],
|
||||
"_jc_meta": {
|
||||
"parser": "ping",
|
||||
"timestamp": 1661357115.27949,
|
||||
"magic_command": [
|
||||
"ping",
|
||||
"-c2",
|
||||
"192.168.1.252"
|
||||
],
|
||||
"magic_command_exit": 2
|
||||
}
|
||||
}
|
||||
$ echo $?
|
||||
2
|
||||
```
|
||||
|
||||
### Setting Custom Colors via Environment Variable
|
||||
You can specify custom colors via the `JC_COLORS` environment variable. The
|
||||
|
Reference in New Issue
Block a user