mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-15 01:24:29 +02:00
@ -1,5 +1,11 @@
|
||||
jc changelog
|
||||
|
||||
20220304 v1.18.4
|
||||
- Add nmcli command parser tested on linux
|
||||
- Enhance parse error messages at the cli
|
||||
- Add standard and streaming parser list functions to the public API
|
||||
- Enhance python developer documentation formatting
|
||||
|
||||
20220214 v1.18.3
|
||||
- Add rsync command and log file parser tested on linux and macOS
|
||||
- Add rsync command and log file streaming parser tested on linux and macOS
|
||||
|
41
EXAMPLES.md
41
EXAMPLES.md
@ -2387,6 +2387,47 @@ netstat -i | jc --netstat -p # or: jc -p netstat -i
|
||||
}
|
||||
]
|
||||
```
|
||||
### nmcli
|
||||
```bash
|
||||
nmcli connection show ens33 | jc --nmcli -p # or jc -p nmcli connection show ens33
|
||||
```
|
||||
```json
|
||||
[
|
||||
{
|
||||
"connection_id": "ens33",
|
||||
"connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744",
|
||||
"connection_stable_id": null,
|
||||
"connection_type": "802-3-ethernet",
|
||||
"connection_interface_name": "ens33",
|
||||
"connection_autoconnect": "yes",
|
||||
"ip4_address_1": "192.168.71.180/24",
|
||||
"ip4_gateway": "192.168.71.2",
|
||||
"ip4_route_1": {
|
||||
"dst": "0.0.0.0/0",
|
||||
"nh": "192.168.71.2",
|
||||
"mt": 100
|
||||
},
|
||||
"ip4_route_2": {
|
||||
"dst": "192.168.71.0/24",
|
||||
"nh": "0.0.0.0",
|
||||
"mt": 100
|
||||
},
|
||||
"ip4_dns_1": "192.168.71.2",
|
||||
"ip4_domain_1": "localdomain",
|
||||
"dhcp4_option_1": {
|
||||
"name": "broadcast_address",
|
||||
"value": "192.168.71.255"
|
||||
},
|
||||
"ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64",
|
||||
"ip6_gateway": null,
|
||||
"ip6_route_1": {
|
||||
"dst": "fe80::/64",
|
||||
"nh": "::",
|
||||
"mt": 100
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
### ntpq
|
||||
```bash
|
||||
ntpq -p | jc --ntpq -p # or: jc -p ntpq -p
|
||||
|
16
README.md
16
README.md
@ -1,8 +1,6 @@
|
||||

|
||||

|
||||
|
||||
> `jc` was recently featured in the [Console Open Source Newsletter](https://console.substack.com/p/console-89)
|
||||
|
||||
> Check out the `jc` Python [package documentation](https://github.com/kellyjonbrazil/jc/tree/master/docs) for developers
|
||||
|
||||
> Try the `jc` [web demo](https://jc-web-demo.herokuapp.com/)
|
||||
@ -13,7 +11,7 @@ Ansible filter plugin in the `community.general` collection. See this
|
||||
for an example.
|
||||
|
||||
# JC
|
||||
JSON CLI output utility
|
||||
JSON Convert
|
||||
|
||||
`jc` JSONifies the output of many CLI tools and file-types for easier parsing in
|
||||
scripts. See the [**Parsers**](#parsers) section for supported commands and
|
||||
@ -55,16 +53,9 @@ will be a python dictionary, or list of dictionaries, instead of JSON:
|
||||
>>> 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':
|
||||
>>> data[0]['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}]
|
||||
'93.184.216.34'}]
|
||||
```
|
||||
|
||||
> For `jc` Python package documentation, use `help('jc')`, `help('jc.lib')`, or
|
||||
@ -199,6 +190,7 @@ option.
|
||||
- `--lsusb` enables the `lsusb` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/lsusb))
|
||||
- `--mount` enables the `mount` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/mount))
|
||||
- `--netstat` enables the `netstat` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/netstat))
|
||||
- `--nmcli` enables the `nmcli` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/nmcli))
|
||||
- `--ntpq` enables the `ntpq -p` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ntpq))
|
||||
- `--passwd` enables the `/etc/passwd` file parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/passwd))
|
||||
- `--ping` enables the `ping` and `ping6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ping))
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# Generate docs.md
|
||||
# requires pydoc-markdown 4.5.0
|
||||
# requires pydoc-markdown 4.6.1
|
||||
readme_config=$(cat <<'EOF'
|
||||
{
|
||||
"processors": [
|
||||
@ -18,7 +18,7 @@ readme_config=$(cat <<'EOF'
|
||||
"Class": 3,
|
||||
"Method": 3,
|
||||
"Function": 3,
|
||||
"Data": 3
|
||||
"Variable": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -43,7 +43,7 @@ toc_config=$(cat <<'EOF'
|
||||
"Class": 3,
|
||||
"Method": 3,
|
||||
"Function": 3,
|
||||
"Data": 3
|
||||
"Variable": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -68,7 +68,7 @@ parser_config=$(cat <<'EOF'
|
||||
"Class": 3,
|
||||
"Method": 3,
|
||||
"Function": 3,
|
||||
"Data": 3
|
||||
"Variable": 3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
docs/lib.md
38
docs/lib.md
@ -4,6 +4,8 @@
|
||||
* [parse](#jc.lib.parse)
|
||||
* [parser\_mod\_list](#jc.lib.parser_mod_list)
|
||||
* [plugin\_parser\_mod\_list](#jc.lib.plugin_parser_mod_list)
|
||||
* [standard\_parser\_mod\_list](#jc.lib.standard_parser_mod_list)
|
||||
* [streaming\_parser\_mod\_list](#jc.lib.streaming_parser_mod_list)
|
||||
* [parser\_info](#jc.lib.parser_info)
|
||||
* [all\_parser\_info](#jc.lib.all_parser_info)
|
||||
* [get\_help](#jc.lib.get_help)
|
||||
@ -12,7 +14,7 @@
|
||||
|
||||
# jc.lib
|
||||
|
||||
jc - JSON CLI output utility
|
||||
jc - JSON Convert
|
||||
JC lib module
|
||||
|
||||
<a id="jc.lib.parse"></a>
|
||||
@ -20,7 +22,12 @@ JC lib module
|
||||
### parse
|
||||
|
||||
```python
|
||||
def parse(parser_mod_name: str, data: Union[str, Iterable[str]], quiet: bool = False, raw: bool = False, ignore_exceptions: bool = None, **kwargs) -> Union[Dict, List[Dict], Iterator[Dict]]
|
||||
def parse(parser_mod_name: str,
|
||||
data: Union[str, Iterable[str]],
|
||||
quiet: bool = False,
|
||||
raw: bool = False,
|
||||
ignore_exceptions: bool = None,
|
||||
**kwargs) -> Union[Dict, List[Dict], Iterator[Dict]]
|
||||
```
|
||||
|
||||
Parse the string data using the supplied parser module.
|
||||
@ -34,9 +41,7 @@ Example:
|
||||
>>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022')
|
||||
{'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...}
|
||||
|
||||
To get a list of available parser module names, use `parser_mod_list()`
|
||||
or `plugin_parser_mod_list()`. `plugin_parser_mod_list()` is a subset
|
||||
of `parser_mod_list()`.
|
||||
To get a list of available parser module names, use `parser_mod_list()`.
|
||||
|
||||
You can also use the lower-level parser modules directly:
|
||||
|
||||
@ -100,6 +105,29 @@ def plugin_parser_mod_list() -> List[str]
|
||||
Returns a list of plugin parser module names. This function is a
|
||||
subset of `parser_mod_list()`.
|
||||
|
||||
<a id="jc.lib.standard_parser_mod_list"></a>
|
||||
|
||||
### standard\_parser\_mod\_list
|
||||
|
||||
```python
|
||||
def standard_parser_mod_list() -> List[str]
|
||||
```
|
||||
|
||||
Returns a list of standard parser module names. This function is a
|
||||
subset of `parser_mod_list()` and does not contain any streaming
|
||||
parsers.
|
||||
|
||||
<a id="jc.lib.streaming_parser_mod_list"></a>
|
||||
|
||||
### streaming\_parser\_mod\_list
|
||||
|
||||
```python
|
||||
def streaming_parser_mod_list() -> List[str]
|
||||
```
|
||||
|
||||
Returns a list of streaming parser module names. This function is a
|
||||
subset of `parser_mod_list()`.
|
||||
|
||||
<a id="jc.lib.parser_info"></a>
|
||||
|
||||
### parser\_info
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.acpi
|
||||
|
||||
jc - JSON CLI output utility `acpi` command output parser
|
||||
jc - JSON Convert `acpi` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.airport
|
||||
|
||||
jc - JSON CLI output utility `airport -I` command output parser
|
||||
jc - JSON Convert `airport -I` command output parser
|
||||
|
||||
The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.airport\_s
|
||||
|
||||
jc - JSON CLI output utility `airport -s` command output parser
|
||||
jc - JSON Convert `airport -s` command output parser
|
||||
|
||||
The `airport` program can be found at `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport`.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.arp
|
||||
|
||||
jc - JSON CLI output utility `arp` command output parser
|
||||
jc - JSON Convert `arp` command output parser
|
||||
|
||||
Supports `arp` and `arp -a` output.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.blkid
|
||||
|
||||
jc - JSON CLI output utility `blkid` command output parser
|
||||
jc - JSON Convert `blkid` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.cksum
|
||||
|
||||
jc - JSON CLI output utility `cksum` command output parser
|
||||
jc - JSON Convert `cksum` command output parser
|
||||
|
||||
This parser works with the following checksum calculation utilities:
|
||||
- `sum`
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.crontab
|
||||
|
||||
jc - JSON CLI output utility `crontab -l` command output and crontab
|
||||
jc - JSON Convert `crontab -l` command output and crontab
|
||||
file parser
|
||||
|
||||
Supports `crontab -l` command output and crontab files.
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.crontab\_u
|
||||
|
||||
jc - JSON CLI output utility `crontab -l` command output and crontab
|
||||
jc - JSON Convert `crontab -l` command output and crontab
|
||||
file parser
|
||||
|
||||
This version of the `crontab -l` parser supports output that contains user
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.csv
|
||||
|
||||
jc - JSON CLI output utility `csv` file parser
|
||||
jc - JSON Convert `csv` file parser
|
||||
|
||||
The `csv` parser will attempt to automatically detect the delimiter
|
||||
character. If the delimiter cannot be detected it will default to comma.
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.csv\_s
|
||||
|
||||
jc - JSON CLI output utility `csv` file streaming parser
|
||||
jc - JSON Convert `csv` file streaming parser
|
||||
|
||||
> This streaming parser outputs JSON Lines
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.date
|
||||
|
||||
jc - JSON CLI output utility `date` command output parser
|
||||
jc - JSON Convert `date` command output parser
|
||||
|
||||
The `epoch` calculated timestamp field is naive. (i.e. based on the local
|
||||
time of the system the parser is run on)
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.df
|
||||
|
||||
jc - JSON CLI output utility `df` command output parser
|
||||
jc - JSON Convert `df` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.dig
|
||||
|
||||
jc - JSON CLI output utility `dig` command output parser
|
||||
jc - JSON Convert `dig` command output parser
|
||||
|
||||
Options supported:
|
||||
- `+noall +answer` options are supported in cases where only the answer
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.dir
|
||||
|
||||
jc - JSON CLI output utility `dir` command output parser
|
||||
jc - JSON Convert `dir` command output parser
|
||||
|
||||
Options supported:
|
||||
- `/T timefield`
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.dmidecode
|
||||
|
||||
jc - JSON CLI output utility `dmidecode` command output parser
|
||||
jc - JSON Convert `dmidecode` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.dpkg\_l
|
||||
|
||||
jc - JSON CLI output utility `dpkg -l` command output parser
|
||||
jc - JSON Convert `dpkg -l` command output parser
|
||||
|
||||
Set the `COLUMNS` environment variable to a large value to avoid field
|
||||
truncation. For example:
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.du
|
||||
|
||||
jc - JSON CLI output utility `du` command output parser
|
||||
jc - JSON Convert `du` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.env
|
||||
|
||||
jc - JSON CLI output utility `env` and `printenv` command output parser
|
||||
jc - JSON Convert `env` and `printenv` command output parser
|
||||
|
||||
This parser will output a list of dictionaries each containing `name` and
|
||||
`value` keys. If you would like a simple dictionary output, then use the
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.file
|
||||
|
||||
jc - JSON CLI output utility `file` command output parser
|
||||
jc - JSON Convert `file` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.finger
|
||||
|
||||
jc - JSON CLI output utility `finger` command output parser
|
||||
jc - JSON Convert `finger` command output parser
|
||||
|
||||
Supports `-s` output option. Does not support the `-l` detail option.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.free
|
||||
|
||||
jc - JSON CLI output utility `free` command output parser
|
||||
jc - JSON Convert `free` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.fstab
|
||||
|
||||
jc - JSON CLI output utility `fstab` file parser
|
||||
jc - JSON Convert `fstab` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.group
|
||||
|
||||
jc - JSON CLI output utility `/etc/group` file parser
|
||||
jc - JSON Convert `/etc/group` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.gshadow
|
||||
|
||||
jc - JSON CLI output utility `/etc/gshadow` file parser
|
||||
jc - JSON Convert `/etc/gshadow` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.hash
|
||||
|
||||
jc - JSON CLI output utility `hash` command output parser
|
||||
jc - JSON Convert `hash` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.hashsum
|
||||
|
||||
jc - JSON CLI output utility `hash sum` command output parser
|
||||
jc - JSON Convert `hash sum` command output parser
|
||||
|
||||
This parser works with the following hash calculation utilities:
|
||||
- `md5`
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.hciconfig
|
||||
|
||||
jc - JSON CLI output utility `hciconfig` command output parser
|
||||
jc - JSON Convert `hciconfig` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.history
|
||||
|
||||
jc - JSON CLI output utility `history` command output parser
|
||||
jc - JSON Convert `history` command output parser
|
||||
|
||||
This parser will output a list of dictionaries each containing `line` and
|
||||
`command` keys. If you would like a simple dictionary output, then use the
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.hosts
|
||||
|
||||
jc - JSON CLI output utility `/etc/hosts` file parser
|
||||
jc - JSON Convert `/etc/hosts` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.id
|
||||
|
||||
jc - JSON CLI output utility `id` command output parser
|
||||
jc - JSON Convert `id` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.ifconfig
|
||||
|
||||
jc - JSON CLI output utility `ifconfig` command output parser
|
||||
jc - JSON Convert `ifconfig` command output parser
|
||||
|
||||
Note: No `ifconfig` options are supported.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.ini
|
||||
|
||||
jc - JSON CLI output utility `INI` file parser
|
||||
jc - JSON Convert `INI` file parser
|
||||
|
||||
Parses standard `INI` files and files containing simple key/value pairs.
|
||||
Delimiter can be `=` or `:`. Missing values are supported. Comment prefix
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.iostat
|
||||
|
||||
jc - JSON CLI output utility `iostat` command output parser
|
||||
jc - JSON Convert `iostat` command output parser
|
||||
|
||||
Note: `iostat` version 11 and higher include a JSON output option
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.iostat\_s
|
||||
|
||||
jc - JSON CLI output utility `iostat` command output streaming parser
|
||||
jc - JSON Convert `iostat` command output streaming parser
|
||||
|
||||
> This streaming parser outputs JSON Lines
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.iptables
|
||||
|
||||
jc - JSON CLI output utility `iptables` command output parser
|
||||
jc - JSON Convert `iptables` command output parser
|
||||
|
||||
Supports `-vLn` and `--line-numbers` for all tables.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.iw\_scan
|
||||
|
||||
jc - JSON CLI output utility `iw dev <device> scan` command output parser
|
||||
jc - JSON Convert `iw dev <device> scan` command output parser
|
||||
|
||||
This parser is considered beta quality. Not all fields are parsed and there
|
||||
are not enough samples to test.
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.jar\_manifest
|
||||
|
||||
jc - JSON CLI output utility `MANIFEST.MF` file parser
|
||||
jc - JSON Convert `MANIFEST.MF` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.jobs
|
||||
|
||||
jc - JSON CLI output utility `jobs` command output parser
|
||||
jc - JSON Convert `jobs` command output parser
|
||||
|
||||
Also supports the `-l` option.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.kv
|
||||
|
||||
jc - JSON CLI output utility `Key/Value` file parser
|
||||
jc - JSON Convert `Key/Value` file parser
|
||||
|
||||
Supports files containing simple key/value pairs. Delimiter can be `=` or
|
||||
`:`. Missing values are supported. Comment prefix can be `#` or `;`.
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.last
|
||||
|
||||
jc - JSON CLI output utility `last` and `lastb` command output parser
|
||||
jc - JSON Convert `last` and `lastb` command output parser
|
||||
|
||||
Supports `-w` and `-F` options.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.ls
|
||||
|
||||
jc - JSON CLI output utility `ls` and `vdir` command output parser
|
||||
jc - JSON Convert `ls` and `vdir` command output parser
|
||||
|
||||
Options supported:
|
||||
- `lbaR1`
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.ls\_s
|
||||
|
||||
jc - JSON CLI output utility `ls` and `vdir` command output streaming
|
||||
jc - JSON Convert `ls` and `vdir` command output streaming
|
||||
parser
|
||||
|
||||
> This streaming parser outputs JSON Lines
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.lsblk
|
||||
|
||||
jc - JSON CLI output utility `lsblk` command output parser
|
||||
jc - JSON Convert `lsblk` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.lsmod
|
||||
|
||||
jc - JSON CLI output utility `lsmod` command output parser
|
||||
jc - JSON Convert `lsmod` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.lsof
|
||||
|
||||
jc - JSON CLI output utility `lsof` command output parser
|
||||
jc - JSON Convert `lsof` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.lsusb
|
||||
|
||||
jc - JSON CLI output utility `lsusb` command output parser
|
||||
jc - JSON Convert `lsusb` command output parser
|
||||
|
||||
Supports the `-v` option or no options.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.mount
|
||||
|
||||
jc - JSON CLI output utility `mount` command output parser
|
||||
jc - JSON Convert `mount` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.netstat
|
||||
|
||||
jc - JSON CLI output utility `netstat` command output parser
|
||||
jc - JSON Convert `netstat` command output parser
|
||||
|
||||
Caveats:
|
||||
- Use of multiple `l` options is not supported on OSX (e.g. `netstat -rlll`)
|
||||
|
176
docs/parsers/nmcli.md
Normal file
176
docs/parsers/nmcli.md
Normal file
@ -0,0 +1,176 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
<a id="jc.parsers.nmcli"></a>
|
||||
|
||||
# jc.parsers.nmcli
|
||||
|
||||
jc - JSON Convert `nmcli` command output parser
|
||||
|
||||
Supports the following `nmcli` subcommands:
|
||||
- `nmcli general`
|
||||
- `nmcli general permissions`
|
||||
- `nmcli connection`
|
||||
- `nmcli connection show <device_name>`
|
||||
- `nmcli device`
|
||||
- `nmcli device show`
|
||||
- `nmcli device show <device_name>`
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ nmcli device show lo | jc --nmcli
|
||||
|
||||
or
|
||||
|
||||
$ jc nmcli device show lo
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc
|
||||
result = jc.parse('nmcli', nmcli_command_output)
|
||||
|
||||
or
|
||||
|
||||
import jc.parsers.nmcli
|
||||
result = jc.parsers.nmcli.parse(nmcli_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
Because there are so many options, the schema is not strictly defined.
|
||||
Integer and Float value conversions are attempted and the original
|
||||
values are kept if they fail. If you don't want automatic conversion,
|
||||
then use the -r or raw=True option to disable it.
|
||||
|
||||
The structure is flat, for the most part, but there are a couple of
|
||||
"well-known" keys that are further parsed into objects for convenience.
|
||||
These are documented below.
|
||||
|
||||
[
|
||||
{
|
||||
"<key>": string/integer/float, [0]
|
||||
"dhcp4_option_x": {
|
||||
"name": string,
|
||||
"value": string/integer/float,
|
||||
},
|
||||
"dhcp6_option_x": {
|
||||
"name": string,
|
||||
"value": string/integer/float,
|
||||
},
|
||||
"ip4_route_x": {
|
||||
"dst": string,
|
||||
"nh": string,
|
||||
"mt": integer
|
||||
},
|
||||
"ip6_route_x": {
|
||||
"dst": string,
|
||||
"nh": string,
|
||||
"mt": integer,
|
||||
"table": integer
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
[0] all values of `---` are converted to null
|
||||
|
||||
Examples:
|
||||
|
||||
$ nmcli connection show ens33 | jc --nmcli -p
|
||||
[
|
||||
{
|
||||
"connection_id": "ens33",
|
||||
"connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744",
|
||||
"connection_stable_id": null,
|
||||
"connection_type": "802-3-ethernet",
|
||||
"connection_interface_name": "ens33",
|
||||
"connection_autoconnect": "yes",
|
||||
...
|
||||
"ip4_address_1": "192.168.71.180/24",
|
||||
"ip4_gateway": "192.168.71.2",
|
||||
"ip4_route_1": {
|
||||
"dst": "0.0.0.0/0",
|
||||
"nh": "192.168.71.2",
|
||||
"mt": 100
|
||||
},
|
||||
"ip4_route_2": {
|
||||
"dst": "192.168.71.0/24",
|
||||
"nh": "0.0.0.0",
|
||||
"mt": 100
|
||||
},
|
||||
"ip4_dns_1": "192.168.71.2",
|
||||
"ip4_domain_1": "localdomain",
|
||||
"dhcp4_option_1": {
|
||||
"name": "broadcast_address",
|
||||
"value": "192.168.71.255"
|
||||
},
|
||||
...
|
||||
"ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64",
|
||||
"ip6_gateway": null,
|
||||
"ip6_route_1": {
|
||||
"dst": "fe80::/64",
|
||||
"nh": "::",
|
||||
"mt": 100
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
$ nmcli connection show ens33 | jc --nmcli -p -r
|
||||
[
|
||||
{
|
||||
"connection_id": "ens33",
|
||||
"connection_uuid": "d92ece08-9e02-47d5-b2d2-92c80e155744",
|
||||
"connection_stable_id": null,
|
||||
"connection_type": "802-3-ethernet",
|
||||
"connection_interface_name": "ens33",
|
||||
"connection_autoconnect": "yes",
|
||||
...
|
||||
"ip4_address_1": "192.168.71.180/24",
|
||||
"ip4_gateway": "192.168.71.2",
|
||||
"ip4_route_1": {
|
||||
"dst": "0.0.0.0/0",
|
||||
"nh": "192.168.71.2",
|
||||
"mt": "100"
|
||||
},
|
||||
"ip4_route_2": {
|
||||
"dst": "192.168.71.0/24",
|
||||
"nh": "0.0.0.0",
|
||||
"mt": "100"
|
||||
},
|
||||
"ip4_dns_1": "192.168.71.2",
|
||||
"ip4_domain_1": "localdomain",
|
||||
"dhcp4_option_1": {
|
||||
"name": "broadcast_address",
|
||||
"value": "192.168.71.255"
|
||||
},
|
||||
...
|
||||
"ip6_address_1": "fe80::c1cb:715d:bc3e:b8a0/64",
|
||||
"ip6_gateway": null,
|
||||
"ip6_route_1": {
|
||||
"dst": "fe80::/64",
|
||||
"nh": "::",
|
||||
"mt": "100"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
<a id="jc.parsers.nmcli.parse"></a>
|
||||
|
||||
### parse
|
||||
|
||||
```python
|
||||
def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict]
|
||||
```
|
||||
|
||||
Main text parsing function
|
||||
|
||||
Parameters:
|
||||
|
||||
data: (string) text data to parse
|
||||
raw: (boolean) unprocessed output if True
|
||||
quiet: (boolean) suppress warning messages if True
|
||||
|
||||
Returns:
|
||||
|
||||
List of Dictionaries. Raw or processed structured data.
|
||||
|
||||
### Parser Information
|
||||
Compatibility: linux
|
||||
|
||||
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.ntpq
|
||||
|
||||
jc - JSON CLI output utility `ntpq -p` command output parser
|
||||
jc - JSON Convert `ntpq -p` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.passwd
|
||||
|
||||
jc - JSON CLI output utility `/etc/passwd` file Parser
|
||||
jc - JSON Convert `/etc/passwd` file Parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.ping
|
||||
|
||||
jc - JSON CLI output utility `ping` command output parser
|
||||
jc - JSON Convert `ping` command output parser
|
||||
|
||||
Supports `ping` and `ping6` output.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.ping\_s
|
||||
|
||||
jc - JSON CLI output utility `ping` command output streaming parser
|
||||
jc - JSON Convert `ping` command output streaming parser
|
||||
|
||||
> This streaming parser outputs JSON Lines
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.pip\_list
|
||||
|
||||
jc - JSON CLI output utility `pip-list` command output parser
|
||||
jc - JSON Convert `pip-list` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.pip\_show
|
||||
|
||||
jc - JSON CLI output utility `pip-show` command output parser
|
||||
jc - JSON Convert `pip-show` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.ps
|
||||
|
||||
jc - JSON CLI output utility `ps` command output parser
|
||||
jc - JSON Convert `ps` command output parser
|
||||
|
||||
`ps` options supported:
|
||||
- `ef`
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.route
|
||||
|
||||
jc - JSON CLI output utility `route` command output parser
|
||||
jc - JSON Convert `route` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.rpm\_qi
|
||||
|
||||
jc - JSON CLI output utility `rpm -qi` command output parser
|
||||
jc - JSON Convert `rpm -qi` command output parser
|
||||
|
||||
Works with `rpm -qi [package]` or `rpm -qia`.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.rsync
|
||||
|
||||
jc - JSON CLI output utility `rsync` command output parser
|
||||
jc - JSON Convert `rsync` command output parser
|
||||
|
||||
Supports the `-i` or `--itemize-changes` options with all levels of
|
||||
verbosity. This parser will process the STDOUT output or a log file
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.rsync\_s
|
||||
|
||||
jc - JSON CLI output utility `rsync` command output streaming parser
|
||||
jc - JSON Convert `rsync` command output streaming parser
|
||||
|
||||
> This streaming parser outputs JSON Lines
|
||||
|
||||
@ -99,7 +99,10 @@ Examples:
|
||||
|
||||
```python
|
||||
@add_jc_meta
|
||||
def parse(data: Iterable[str], raw: bool = False, quiet: bool = False, ignore_exceptions: bool = False) -> Union[Iterable[Dict], tuple]
|
||||
def parse(data: Iterable[str],
|
||||
raw: bool = False,
|
||||
quiet: bool = False,
|
||||
ignore_exceptions: bool = False) -> Union[Iterable[Dict], tuple]
|
||||
```
|
||||
|
||||
Main text parsing generator function. Returns an iterator object.
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.sfdisk
|
||||
|
||||
jc - JSON CLI output utility `sfdisk` command output parser
|
||||
jc - JSON Convert `sfdisk` command output parser
|
||||
|
||||
Supports the following `sfdisk` options:
|
||||
- `-l`
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.shadow
|
||||
|
||||
jc - JSON CLI output utility `/etc/shadow` file parser
|
||||
jc - JSON Convert `/etc/shadow` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.ss
|
||||
|
||||
jc - JSON CLI output utility `ss` command output parser
|
||||
jc - JSON Convert `ss` command output parser
|
||||
|
||||
Extended information options like -e and -p are not supported and may cause
|
||||
parsing irregularities.
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.stat
|
||||
|
||||
jc - JSON CLI output utility `stat` command output parser
|
||||
jc - JSON Convert `stat` command output parser
|
||||
|
||||
The `xxx_epoch` calculated timestamp fields are naive. (i.e. based on the
|
||||
local time of the system the parser is run on)
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.stat\_s
|
||||
|
||||
jc - JSON CLI output utility `stat` command output streaming parser
|
||||
jc - JSON Convert `stat` command output streaming parser
|
||||
|
||||
> This streaming parser outputs JSON Lines
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.sysctl
|
||||
|
||||
jc - JSON CLI output utility `sysctl -a` command output parser
|
||||
jc - JSON Convert `sysctl -a` command output parser
|
||||
|
||||
Note: Since `sysctl` output is not easily parsable only a very simple
|
||||
key/value object will be output. An attempt is made to convert obvious
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.systemctl
|
||||
|
||||
jc - JSON CLI output utility `systemctl` command output parser
|
||||
jc - JSON Convert `systemctl` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.systemctl\_lj
|
||||
|
||||
jc - JSON CLI output utility `systemctl list-jobs` command output parser
|
||||
jc - JSON Convert `systemctl list-jobs` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.systemctl\_ls
|
||||
|
||||
jc - JSON CLI output utility `systemctl list-sockets` command output
|
||||
jc - JSON Convert `systemctl list-sockets` command output
|
||||
parser
|
||||
|
||||
Usage (cli):
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.systemctl\_luf
|
||||
|
||||
jc - JSON CLI output utility `systemctl list-unit-files` command output
|
||||
jc - JSON Convert `systemctl list-unit-files` command output
|
||||
parser
|
||||
|
||||
Usage (cli):
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.systeminfo
|
||||
|
||||
jc - JSON CLI output utility `systeminfo` command output parser
|
||||
jc - JSON Convert `systeminfo` command output parser
|
||||
|
||||
Blank or missing elements are set to `null`.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.time
|
||||
|
||||
jc - JSON CLI output utility `/usr/bin/time` command output parser
|
||||
jc - JSON Convert `/usr/bin/time` command output parser
|
||||
|
||||
Output from `/usr/bin/time` is sent to `STDERR`, so the `-o` option can be
|
||||
used to redirect the output to a file that can be read by `jc`.
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.timedatectl
|
||||
|
||||
jc - JSON CLI output utility `timedatectl` command output parser
|
||||
jc - JSON Convert `timedatectl` command output parser
|
||||
|
||||
The `epoch_utc` calculated timestamp field is timezone-aware and is only
|
||||
available if the `universal_time` field is available.
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.tracepath
|
||||
|
||||
jc - JSON CLI output utility `tracepath` command output parser
|
||||
jc - JSON Convert `tracepath` command output parser
|
||||
|
||||
Supports `tracepath` and `tracepath6` output.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.traceroute
|
||||
|
||||
jc - JSON CLI output utility `traceroute` command output parser
|
||||
jc - JSON Convert `traceroute` command output parser
|
||||
|
||||
Supports `traceroute` and `traceroute6` output.
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.ufw
|
||||
|
||||
jc - JSON CLI output utility `ufw status` command output parser
|
||||
jc - JSON Convert `ufw status` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.ufw\_appinfo
|
||||
|
||||
jc - JSON CLI output utility `ufw app info [application]` command
|
||||
jc - JSON Convert `ufw app info [application]` command
|
||||
output parser
|
||||
|
||||
Supports individual apps via `ufw app info [application]` and all apps list
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.uname
|
||||
|
||||
jc - JSON CLI output utility `uname -a` command output parser
|
||||
jc - JSON Convert `uname -a` command output parser
|
||||
|
||||
Note: Must use `uname -a`
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
# jc.parsers.universal
|
||||
|
||||
jc - JSON CLI output utility universal Parsers
|
||||
jc - JSON Convert universal parsers
|
||||
|
||||
<a id="jc.parsers.universal.simple_table_parse"></a>
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.upower
|
||||
|
||||
jc - JSON CLI output utility `upower` command output parser
|
||||
jc - JSON Convert `upower` command output parser
|
||||
|
||||
The `updated_epoch` calculated timestamp field is naive. (i.e. based on the
|
||||
local time of the system the parser is run on)
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.uptime
|
||||
|
||||
jc - JSON CLI output utility `uptime` command output parser
|
||||
jc - JSON Convert `uptime` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.vmstat
|
||||
|
||||
jc - JSON CLI output utility `vmstat` command output parser
|
||||
jc - JSON Convert `vmstat` command output parser
|
||||
|
||||
Options supported: `-a`, `-w`, `-d`, `-t`
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.vmstat\_s
|
||||
|
||||
jc - JSON CLI output utility `vmstat` command output streaming parser
|
||||
jc - JSON Convert `vmstat` command output streaming parser
|
||||
|
||||
> This streaming parser outputs JSON Lines
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.w
|
||||
|
||||
jc - JSON CLI output utility `w` command output parser
|
||||
jc - JSON Convert `w` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.wc
|
||||
|
||||
jc - JSON CLI output utility `wc` command output parser
|
||||
jc - JSON Convert `wc` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.who
|
||||
|
||||
jc - JSON CLI output utility `who` command output parser
|
||||
jc - JSON Convert `who` command output parser
|
||||
|
||||
Accepts any of the following who options (or no options): `-aTH`
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.xml
|
||||
|
||||
jc - JSON CLI output utility `XML` file parser
|
||||
jc - JSON Convert `XML` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.xrandr
|
||||
|
||||
jc - JSON CLI output utility `xrandr` command output parser
|
||||
jc - JSON Convert `xrandr` command output parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.yaml
|
||||
|
||||
jc - JSON CLI output utility `YAML` file parser
|
||||
jc - JSON Convert `YAML` file parser
|
||||
|
||||
Usage (cli):
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
# jc.parsers.zipinfo
|
||||
|
||||
jc - JSON CLI output utility `zipinfo` command output parser
|
||||
jc - JSON Convert `zipinfo` command output parser
|
||||
|
||||
Options supported:
|
||||
- none
|
||||
@ -107,4 +107,4 @@ Returns:
|
||||
### Parser Information
|
||||
Compatibility: linux, darwin
|
||||
|
||||
Version 0.01 by Matt J (https://github.com/listuser)
|
||||
Version 1.0 by Matt J (https://github.com/listuser)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# jc
|
||||
|
||||
JC - JSON CLI output utility
|
||||
JC - JSON Convert
|
||||
|
||||
* kellyjonbrazil@gmail.com
|
||||
|
||||
@ -26,9 +26,9 @@ https://github.com/kellyjonbrazil/jc/tree/master/docs
|
||||
|
||||
### Specific Version
|
||||
|
||||
Replace `{{full_version_number}}` - e.g. `1.17.7`:
|
||||
Replace `<full_version_number>` - e.g. `1.17.7`:
|
||||
|
||||
`https://github.com/kellyjonbrazil/jc/tree/v{{full_version_number}}/docs`
|
||||
`https://github.com/kellyjonbrazil/jc/tree/v<full_version_number>/docs`
|
||||
|
||||
Specific versions can also be selected by tag in the branch dropdown menu.
|
||||
|
||||
@ -57,29 +57,65 @@ modules directly:
|
||||
|
||||
## Available Functions
|
||||
|
||||
Use `help(jc.lib)` for details:
|
||||
Use `help(jc.lib)` for details.
|
||||
|
||||
parse(parser_module_name: str, data: str | Iterable)
|
||||
-> dict | list[dict] | Iterable[dict]
|
||||
High-level API to easily access the parser. This API will find both
|
||||
built-in parsers and local plugin parsers.
|
||||
### parse
|
||||
|
||||
parse(
|
||||
parser_module_name: str,
|
||||
data: str | Iterable
|
||||
) -> dict | list[dict] | Iterable[dict]
|
||||
|
||||
High-level API to easily access the parser. This API will find both
|
||||
built-in parsers and local plugin parsers.
|
||||
|
||||
### parser_info
|
||||
|
||||
parser_info(parser_module_name: str) -> dict
|
||||
Get the metadata for a particular parser.
|
||||
|
||||
Get the metadata for a particular parser.
|
||||
|
||||
### all_parser_info
|
||||
|
||||
all_parser_info() -> list[dict]
|
||||
Get the metadata for all parsers.
|
||||
|
||||
Get the metadata for all parsers.
|
||||
|
||||
### get_help
|
||||
|
||||
get_help(parser_module_name: str) -> None
|
||||
Convenience function to display the help screen for a parser using
|
||||
its module name.
|
||||
|
||||
Convenience function to display the help screen for a parser using
|
||||
its module name.
|
||||
|
||||
### parser_mod_list
|
||||
|
||||
parser_mod_list() -> list
|
||||
Get a list of all available parser module names to be used in
|
||||
parse(), parser_info(), and get_help().
|
||||
|
||||
Get a list of all available parser module names to be used in
|
||||
`parse()`, `parser_info()`, and `get_help()`.
|
||||
|
||||
### plugin_parser_mod_list
|
||||
|
||||
plugin_parser_mod_list() -> list
|
||||
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().
|
||||
|
||||
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()`.
|
||||
|
||||
### standard_parser_mod_list
|
||||
|
||||
standard_parser_mod_list() -> list
|
||||
|
||||
Get a list of standard parser module names to be used in
|
||||
`parse()`, `parser_info()`, and `get_help()`. This list is a subset of
|
||||
`parser_mod_list()` and does not contain any streaming parsers.
|
||||
|
||||
### streaming_parser_mod_list
|
||||
|
||||
streaming_parser_mod_list() -> list
|
||||
|
||||
Get a list of streaming parser module names to be used in
|
||||
`parse()`, `parser_info()`, and `get_help()`. This list is a subset of
|
||||
`parser_mod_list()`.
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
# jc.streaming
|
||||
|
||||
jc - JSON CLI output utility streaming utils
|
||||
jc - JSON Convert streaming utils
|
||||
|
||||
<a id="jc.streaming.streaming_input_type_check"></a>
|
||||
|
||||
@ -105,7 +105,8 @@ In all cases above:
|
||||
### raise\_or\_yield
|
||||
|
||||
```python
|
||||
def raise_or_yield(ignore_exceptions: bool, e: BaseException, line: str) -> tuple
|
||||
def raise_or_yield(ignore_exceptions: bool, e: BaseException,
|
||||
line: str) -> tuple
|
||||
```
|
||||
|
||||
Return the exception object and line string if ignore_exceptions is
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
# jc.utils
|
||||
|
||||
jc - JSON CLI output utility utils
|
||||
jc - JSON Convert utils
|
||||
|
||||
<a id="jc.utils.warning_message"></a>
|
||||
|
||||
@ -63,7 +63,9 @@ Returns:
|
||||
### compatibility
|
||||
|
||||
```python
|
||||
def compatibility(mod_name: str, compatible: List, quiet: bool = False) -> None
|
||||
def compatibility(mod_name: str,
|
||||
compatible: List,
|
||||
quiet: bool = False) -> None
|
||||
```
|
||||
|
||||
Checks for the parser's compatibility with the running OS
|
||||
@ -184,7 +186,8 @@ class timestamp()
|
||||
### \_\_init\_\_
|
||||
|
||||
```python
|
||||
def __init__(datetime_string: str, format_hint: Union[List, Tuple, None] = None) -> None
|
||||
def __init__(datetime_string: str,
|
||||
format_hint: Union[List, Tuple, None] = None) -> None
|
||||
```
|
||||
|
||||
Input a datetime text string of several formats and convert to a
|
||||
|
@ -1,4 +1,4 @@
|
||||
"""JC - JSON CLI output utility
|
||||
"""JC - JSON Convert
|
||||
|
||||
* kellyjonbrazil@gmail.com
|
||||
|
||||
@ -22,9 +22,9 @@ https://github.com/kellyjonbrazil/jc/tree/master/docs
|
||||
|
||||
### Specific Version
|
||||
|
||||
Replace `{{full_version_number}}` - e.g. `1.17.7`:
|
||||
Replace `<full_version_number>` - e.g. `1.17.7`:
|
||||
|
||||
`https://github.com/kellyjonbrazil/jc/tree/v{{full_version_number}}/docs`
|
||||
`https://github.com/kellyjonbrazil/jc/tree/v<full_version_number>/docs`
|
||||
|
||||
Specific versions can also be selected by tag in the branch dropdown menu.
|
||||
|
||||
@ -53,31 +53,68 @@ modules directly:
|
||||
|
||||
## Available Functions
|
||||
|
||||
Use `help(jc.lib)` for details:
|
||||
Use `help(jc.lib)` for details.
|
||||
|
||||
parse(parser_module_name: str, data: str | Iterable)
|
||||
-> dict | list[dict] | Iterable[dict]
|
||||
High-level API to easily access the parser. This API will find both
|
||||
built-in parsers and local plugin parsers.
|
||||
### parse
|
||||
|
||||
parse(
|
||||
parser_module_name: str,
|
||||
data: str | Iterable
|
||||
) -> dict | list[dict] | Iterable[dict]
|
||||
|
||||
High-level API to easily access the parser. This API will find both
|
||||
built-in parsers and local plugin parsers.
|
||||
|
||||
### parser_info
|
||||
|
||||
parser_info(parser_module_name: str) -> dict
|
||||
Get the metadata for a particular parser.
|
||||
|
||||
Get the metadata for a particular parser.
|
||||
|
||||
### all_parser_info
|
||||
|
||||
all_parser_info() -> list[dict]
|
||||
Get the metadata for all parsers.
|
||||
|
||||
Get the metadata for all parsers.
|
||||
|
||||
### get_help
|
||||
|
||||
get_help(parser_module_name: str) -> None
|
||||
Convenience function to display the help screen for a parser using
|
||||
its module name.
|
||||
|
||||
Convenience function to display the help screen for a parser using
|
||||
its module name.
|
||||
|
||||
### parser_mod_list
|
||||
|
||||
parser_mod_list() -> list
|
||||
Get a list of all available parser module names to be used in
|
||||
parse(), parser_info(), and get_help().
|
||||
|
||||
Get a list of all available parser module names to be used in
|
||||
`parse()`, `parser_info()`, and `get_help()`.
|
||||
|
||||
### plugin_parser_mod_list
|
||||
|
||||
plugin_parser_mod_list() -> list
|
||||
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().
|
||||
|
||||
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()`.
|
||||
|
||||
### standard_parser_mod_list
|
||||
|
||||
standard_parser_mod_list() -> list
|
||||
|
||||
Get a list of standard parser module names to be used in
|
||||
`parse()`, `parser_info()`, and `get_help()`. This list is a subset of
|
||||
`parser_mod_list()` and does not contain any streaming parsers.
|
||||
|
||||
### streaming_parser_mod_list
|
||||
|
||||
streaming_parser_mod_list() -> list
|
||||
|
||||
Get a list of streaming parser module names to be used in
|
||||
`parse()`, `parser_info()`, and `get_help()`. This list is a subset of
|
||||
`parser_mod_list()`.
|
||||
"""
|
||||
from .lib import (__version__, parse, parser_mod_list, plugin_parser_mod_list,
|
||||
standard_parser_mod_list, streaming_parser_mod_list,
|
||||
parser_info, all_parser_info, get_help)
|
||||
|
12
jc/cli.py
12
jc/cli.py
@ -1,4 +1,4 @@
|
||||
"""jc - JSON CLI output utility
|
||||
"""jc - JSON Convert
|
||||
JC cli module
|
||||
"""
|
||||
|
||||
@ -11,7 +11,7 @@ import shlex
|
||||
import subprocess
|
||||
import json
|
||||
from .lib import (__version__, all_parser_info, parsers,
|
||||
_parser_argument, _get_parser)
|
||||
_parser_argument, _get_parser, _parser_is_streaming)
|
||||
from . import utils
|
||||
from . import tracebackplus
|
||||
from .exceptions import LibraryNotInstalled, ParseError
|
||||
@ -34,7 +34,7 @@ JC_ERROR_EXIT = 100
|
||||
|
||||
class info():
|
||||
version = __version__
|
||||
description = 'JSON CLI output utility'
|
||||
description = 'JSON Convert'
|
||||
author = 'Kelly Brazil'
|
||||
author_email = 'kellyjonbrazil@gmail.com'
|
||||
website = 'https://github.com/kellyjonbrazil/jc'
|
||||
@ -502,7 +502,7 @@ def main():
|
||||
# differentiate between regular and streaming parsers
|
||||
|
||||
# streaming
|
||||
if getattr(parser.info, 'streaming', None):
|
||||
if _parser_is_streaming(parser):
|
||||
result = parser.parse(sys.stdin,
|
||||
raw=raw,
|
||||
quiet=quiet,
|
||||
@ -539,7 +539,7 @@ def main():
|
||||
utils.error_message([
|
||||
f'Parser issue with {parser_name}:', f'{e.__class__.__name__}: {e}',
|
||||
'If this is the correct parser, try setting the locale to C (LANG=C).',
|
||||
'For details use the -d or -dd option. Use "jc -h" for help.'
|
||||
f'For details use the -d or -dd option. Use "jc -h --{parser_name}" for help.'
|
||||
])
|
||||
sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT))
|
||||
|
||||
@ -563,7 +563,7 @@ def main():
|
||||
f'{parser_name} parser could not parse the input data.',
|
||||
f'{streaming_msg}',
|
||||
'If this is the correct parser, try setting the locale to C (LANG=C).',
|
||||
'For details use the -d or -dd option. Use "jc -h" for help.'
|
||||
f'For details use the -d or -dd option. Use "jc -h --{parser_name}" for help.'
|
||||
])
|
||||
sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT))
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user