mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
doc update
This commit is contained in:
@ -199,6 +199,7 @@ option.
|
|||||||
- `--lsusb` enables the `lsusb` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/lsusb))
|
- `--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))
|
- `--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))
|
- `--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))
|
- `--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))
|
- `--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))
|
- `--ping` enables the `ping` and `ping6` command parser ([documentation](https://kellyjonbrazil.github.io/jc/docs/parsers/ping))
|
||||||
|
172
docs/parsers/nmcli.md
Normal file
172
docs/parsers/nmcli.md
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||||
|
<a id="jc.parsers.nmcli"></a>
|
||||||
|
|
||||||
|
# jc.parsers.nmcli
|
||||||
|
|
||||||
|
jc - JSON CLI output utility `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 best effort. 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,
|
||||||
|
},
|
||||||
|
"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 | 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)
|
@ -342,7 +342,6 @@ def _connection_show_x_parse(data: str) -> List[Dict]:
|
|||||||
if '_route_' in key_n and key_n[-1].isdigit():
|
if '_route_' in key_n and key_n[-1].isdigit():
|
||||||
item[key_n] = _split_routes(item[key_n])
|
item[key_n] = _split_routes(item[key_n])
|
||||||
|
|
||||||
|
|
||||||
if item:
|
if item:
|
||||||
raw_output.append(item)
|
raw_output.append(item)
|
||||||
|
|
||||||
@ -402,7 +401,7 @@ def parse(
|
|||||||
|
|
||||||
# nmcli (second line startswith \t)
|
# nmcli (second line startswith \t)
|
||||||
if data.splitlines()[1].startswith('\t'):
|
if data.splitlines()[1].startswith('\t'):
|
||||||
raise ParseError('Use device, connection, or general subcommands in nmcli.')
|
raise ParseError('Use the device, connection, or general subcommand in nmcli.')
|
||||||
|
|
||||||
# nmcli device show
|
# nmcli device show
|
||||||
# nmcli device show lo
|
# nmcli device show lo
|
||||||
|
7
man/jc.1
7
man/jc.1
@ -1,4 +1,4 @@
|
|||||||
.TH jc 1 2022-02-14 1.18.3 "JSON CLI output utility"
|
.TH jc 1 2022-02-24 1.18.4 "JSON CLI output utility"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
jc \- JSONifies the output of many CLI tools and file-types
|
jc \- JSONifies the output of many CLI tools and file-types
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
@ -257,6 +257,11 @@ Key/Value file parser
|
|||||||
\fB--netstat\fP
|
\fB--netstat\fP
|
||||||
`netstat` command parser
|
`netstat` command parser
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B
|
||||||
|
\fB--nmcli\fP
|
||||||
|
`nmcli` command parser
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B
|
||||||
\fB--ntpq\fP
|
\fB--ntpq\fP
|
||||||
|
Reference in New Issue
Block a user