mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-07 00:57:22 +02:00
add --module-info support to ethtool parser
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
jc changelog
|
||||
|
||||
20240228 v1.25.2
|
||||
- Add `apt-cache show` command parser
|
||||
- Add `needrestart -b` command parser
|
||||
20240301 v1.25.2
|
||||
- Add `apt-cache-show` command parser
|
||||
- Add `apt-get-sqq` command parser
|
||||
- Add `ethtool` command parser
|
||||
- Add `needrestart` command parser
|
||||
- Enhance `df` parser to add human readable output support. Note: the `size`
|
||||
field has been changed to an integer and all size values have been normalized
|
||||
to bytes.
|
||||
|
@ -160,6 +160,7 @@ option.
|
||||
| `--airport` | `airport -I` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/airport) |
|
||||
| `--airport-s` | `airport -s` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/airport_s) |
|
||||
| `--apt-cache-show` | `apt-cache show` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/apt_cache_show) |
|
||||
| `--apt-get-sqq` | `apt-get -sqq` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/apt_get_sqq) |
|
||||
| `--arp` | `arp` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/arp) |
|
||||
| `--asciitable` | ASCII and Unicode table parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/asciitable) |
|
||||
| `--asciitable-m` | multi-line ASCII and Unicode table parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/asciitable_m) |
|
||||
@ -190,6 +191,7 @@ option.
|
||||
| `--efibootmgr` | `efibootmgr` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/efibootmgr) |
|
||||
| `--email-address` | Email Address string parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/email_address) |
|
||||
| `--env` | `env` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/env) |
|
||||
| `--ethtool` | `ethtool` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/ethtool) |
|
||||
| `--file` | `file` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/file) |
|
||||
| `--find` | `find` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/find) |
|
||||
| `--findmnt` | `findmnt` command parser | [details](https://kellyjonbrazil.github.io/jc/docs/parsers/findmnt) |
|
||||
|
@ -3,8 +3,8 @@ _jc()
|
||||
local cur prev words cword jc_commands jc_parsers jc_options \
|
||||
jc_about_options jc_about_mod_options jc_help_options jc_special_options
|
||||
|
||||
jc_commands=(acpi airport apt-cache arp blkid bluetoothctl cbt certbot chage cksum crontab curl date debconf-show df dig dmidecode dpkg du efibootmgr env file findmnt finger free git gpg hciconfig host id ifconfig iostat ip iptables iw iwconfig jobs last lastb ls lsattr lsb_release lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat needrestart netstat nmcli nsd-control ntpq os-prober pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss ssh sshd stat sum swapon sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 tune2fs udevadm ufw uname update-alternatives upower uptime vdir veracrypt vmstat w wc who xrandr zipinfo zpool)
|
||||
jc_parsers=(--acpi --airport --airport-s --apt-cache-show --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --curl-head --date --datetime-iso --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --efibootmgr --email-address --env --file --find --findmnt --finger --free --fstab --git-log --git-log-s --git-ls-remote --gpg --group --gshadow --hash --hashsum --hciconfig --history --host --hosts --http-headers --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --kv-dup --last --ls --ls-s --lsattr --lsb-release --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --needrestart --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --path --path-list --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --pkg-index-apk --pkg-index-deb --plist --postconf --proc --proc-buddyinfo --proc-cmdline --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-tcp --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --resolve-conf --route --rpm-qi --rsync --rsync-s --semver --sfdisk --shadow --srt --ss --ssh-conf --sshd-conf --stat --stat-s --swapon --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --toml --top --top-s --tracepath --traceroute --tune2fs --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --ver --veracrypt --vmstat --vmstat-s --w --wc --who --x509-cert --x509-csr --xml --xrandr --yaml --zipinfo --zpool-iostat --zpool-status)
|
||||
jc_commands=(acpi airport apt-cache apt-get arp blkid bluetoothctl cbt certbot chage cksum crontab curl date debconf-show df dig dmidecode dpkg du efibootmgr env ethtool file findmnt finger free git gpg hciconfig host id ifconfig iostat ip iptables iw iwconfig jobs last lastb ls lsattr lsb_release lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat needrestart netstat nmcli nsd-control ntpq os-prober pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss ssh sshd stat sum swapon sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 tune2fs udevadm ufw uname update-alternatives upower uptime vdir veracrypt vmstat w wc who xrandr zipinfo zpool)
|
||||
jc_parsers=(--acpi --airport --airport-s --apt-cache-show --apt-get-sqq --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --curl-head --date --datetime-iso --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --efibootmgr --email-address --env --ethtool --file --find --findmnt --finger --free --fstab --git-log --git-log-s --git-ls-remote --gpg --group --gshadow --hash --hashsum --hciconfig --history --host --hosts --http-headers --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --kv-dup --last --ls --ls-s --lsattr --lsb-release --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --needrestart --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --path --path-list --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --pkg-index-apk --pkg-index-deb --plist --postconf --proc --proc-buddyinfo --proc-cmdline --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-tcp --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --resolve-conf --route --rpm-qi --rsync --rsync-s --semver --sfdisk --shadow --srt --ss --ssh-conf --sshd-conf --stat --stat-s --swapon --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --toml --top --top-s --tracepath --traceroute --tune2fs --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --ver --veracrypt --vmstat --vmstat-s --w --wc --who --x509-cert --x509-csr --xml --xrandr --yaml --zipinfo --zpool-iostat --zpool-status)
|
||||
jc_options=(--force-color -C --debug -d --monochrome -m --meta-out -M --pretty -p --quiet -q --raw -r --slurp -s --unbuffer -u --yaml-out -y)
|
||||
jc_about_options=(--about -a)
|
||||
jc_about_mod_options=(--pretty -p --yaml-out -y --monochrome -m --force-color -C)
|
||||
|
@ -9,11 +9,12 @@ _jc() {
|
||||
jc_help_options jc_help_options_describe \
|
||||
jc_special_options jc_special_options_describe
|
||||
|
||||
jc_commands=(acpi airport apt-cache arp blkid bluetoothctl cbt certbot chage cksum crontab curl date debconf-show df dig dmidecode dpkg du efibootmgr env file findmnt finger free git gpg hciconfig host id ifconfig iostat ip iptables iw iwconfig jobs last lastb ls lsattr lsb_release lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat needrestart netstat nmcli nsd-control ntpq os-prober pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss ssh sshd stat sum swapon sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 tune2fs udevadm ufw uname update-alternatives upower uptime vdir veracrypt vmstat w wc who xrandr zipinfo zpool)
|
||||
jc_commands=(acpi airport apt-cache apt-get arp blkid bluetoothctl cbt certbot chage cksum crontab curl date debconf-show df dig dmidecode dpkg du efibootmgr env ethtool file findmnt finger free git gpg hciconfig host id ifconfig iostat ip iptables iw iwconfig jobs last lastb ls lsattr lsb_release lsblk lsmod lsof lspci lsusb md5 md5sum mdadm mount mpstat needrestart netstat nmcli nsd-control ntpq os-prober pidstat ping ping6 pip pip3 postconf printenv ps route rpm rsync sfdisk sha1sum sha224sum sha256sum sha384sum sha512sum shasum ss ssh sshd stat sum swapon sysctl systemctl systeminfo timedatectl top tracepath tracepath6 traceroute traceroute6 tune2fs udevadm ufw uname update-alternatives upower uptime vdir veracrypt vmstat w wc who xrandr zipinfo zpool)
|
||||
jc_commands_describe=(
|
||||
'acpi:run "acpi" command with magic syntax.'
|
||||
'airport:run "airport" command with magic syntax.'
|
||||
'apt-cache:run "apt-cache" command with magic syntax.'
|
||||
'apt-get:run "apt-get" command with magic syntax.'
|
||||
'arp:run "arp" command with magic syntax.'
|
||||
'blkid:run "blkid" command with magic syntax.'
|
||||
'bluetoothctl:run "bluetoothctl" command with magic syntax.'
|
||||
@ -32,6 +33,7 @@ _jc() {
|
||||
'du:run "du" command with magic syntax.'
|
||||
'efibootmgr:run "efibootmgr" command with magic syntax.'
|
||||
'env:run "env" command with magic syntax.'
|
||||
'ethtool:run "ethtool" command with magic syntax.'
|
||||
'file:run "file" command with magic syntax.'
|
||||
'findmnt:run "findmnt" command with magic syntax.'
|
||||
'finger:run "finger" command with magic syntax.'
|
||||
@ -119,12 +121,13 @@ _jc() {
|
||||
'zipinfo:run "zipinfo" command with magic syntax.'
|
||||
'zpool:run "zpool" command with magic syntax.'
|
||||
)
|
||||
jc_parsers=(--acpi --airport --airport-s --apt-cache-show --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --curl-head --date --datetime-iso --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --efibootmgr --email-address --env --file --find --findmnt --finger --free --fstab --git-log --git-log-s --git-ls-remote --gpg --group --gshadow --hash --hashsum --hciconfig --history --host --hosts --http-headers --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --kv-dup --last --ls --ls-s --lsattr --lsb-release --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --needrestart --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --path --path-list --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --pkg-index-apk --pkg-index-deb --plist --postconf --proc --proc-buddyinfo --proc-cmdline --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-tcp --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --resolve-conf --route --rpm-qi --rsync --rsync-s --semver --sfdisk --shadow --srt --ss --ssh-conf --sshd-conf --stat --stat-s --swapon --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --toml --top --top-s --tracepath --traceroute --tune2fs --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --ver --veracrypt --vmstat --vmstat-s --w --wc --who --x509-cert --x509-csr --xml --xrandr --yaml --zipinfo --zpool-iostat --zpool-status)
|
||||
jc_parsers=(--acpi --airport --airport-s --apt-cache-show --apt-get-sqq --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --curl-head --date --datetime-iso --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --efibootmgr --email-address --env --ethtool --file --find --findmnt --finger --free --fstab --git-log --git-log-s --git-ls-remote --gpg --group --gshadow --hash --hashsum --hciconfig --history --host --hosts --http-headers --id --ifconfig --ini --ini-dup --iostat --iostat-s --ip-address --iptables --ip-route --iw-scan --iwconfig --jar-manifest --jobs --jwt --kv --kv-dup --last --ls --ls-s --lsattr --lsb-release --lsblk --lsmod --lsof --lspci --lsusb --m3u --mdadm --mount --mpstat --mpstat-s --needrestart --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --path --path-list --pci-ids --pgpass --pidstat --pidstat-s --ping --ping-s --pip-list --pip-show --pkg-index-apk --pkg-index-deb --plist --postconf --proc --proc-buddyinfo --proc-cmdline --proc-consoles --proc-cpuinfo --proc-crypto --proc-devices --proc-diskstats --proc-filesystems --proc-interrupts --proc-iomem --proc-ioports --proc-loadavg --proc-locks --proc-meminfo --proc-modules --proc-mtrr --proc-pagetypeinfo --proc-partitions --proc-slabinfo --proc-softirqs --proc-stat --proc-swaps --proc-uptime --proc-version --proc-vmallocinfo --proc-vmstat --proc-zoneinfo --proc-driver-rtc --proc-net-arp --proc-net-dev --proc-net-dev-mcast --proc-net-if-inet6 --proc-net-igmp --proc-net-igmp6 --proc-net-ipv6-route --proc-net-netlink --proc-net-netstat --proc-net-packet --proc-net-protocols --proc-net-route --proc-net-tcp --proc-net-unix --proc-pid-fdinfo --proc-pid-io --proc-pid-maps --proc-pid-mountinfo --proc-pid-numa-maps --proc-pid-smaps --proc-pid-stat --proc-pid-statm --proc-pid-status --ps --resolve-conf --route --rpm-qi --rsync --rsync-s --semver --sfdisk --shadow --srt --ss --ssh-conf --sshd-conf --stat --stat-s --swapon --sysctl --syslog --syslog-s --syslog-bsd --syslog-bsd-s --systemctl --systemctl-lj --systemctl-ls --systemctl-luf --systeminfo --time --timedatectl --timestamp --toml --top --top-s --tracepath --traceroute --tune2fs --udevadm --ufw --ufw-appinfo --uname --update-alt-gs --update-alt-q --upower --uptime --url --ver --veracrypt --vmstat --vmstat-s --w --wc --who --x509-cert --x509-csr --xml --xrandr --yaml --zipinfo --zpool-iostat --zpool-status)
|
||||
jc_parsers_describe=(
|
||||
'--acpi:`acpi` command parser'
|
||||
'--airport:`airport -I` command parser'
|
||||
'--airport-s:`airport -s` command parser'
|
||||
'--apt-cache-show:`apt-cache show` command parser'
|
||||
'--apt-get-sqq:`apt-get -sqq` command parser'
|
||||
'--arp:`arp` command parser'
|
||||
'--asciitable:ASCII and Unicode table parser'
|
||||
'--asciitable-m:multi-line ASCII and Unicode table parser'
|
||||
@ -155,6 +158,7 @@ _jc() {
|
||||
'--efibootmgr:`efibootmgr` command parser'
|
||||
'--email-address:Email Address string parser'
|
||||
'--env:`env` command parser'
|
||||
'--ethtool:`ethtool` command parser'
|
||||
'--file:`file` command parser'
|
||||
'--find:`find` command parser'
|
||||
'--findmnt:`findmnt` command parser'
|
||||
|
121
docs/parsers/ethtool.md
Normal file
121
docs/parsers/ethtool.md
Normal file
@ -0,0 +1,121 @@
|
||||
[Home](https://kellyjonbrazil.github.io/jc/)
|
||||
<a id="jc.parsers.ethtool"></a>
|
||||
|
||||
# jc.parsers.ethtool
|
||||
|
||||
jc - JSON Convert `ethtool` command output parser
|
||||
|
||||
Supports standard `ethtool` output and the `--module-info` option.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ ethtool <interface> | jc --ethtool
|
||||
$ ethtool --module-info <interface> | jc --ethtool
|
||||
|
||||
or
|
||||
|
||||
$ jc ethtool <interface>
|
||||
$ jc ethtool --module-info <interface>
|
||||
|
||||
Usage (module):
|
||||
|
||||
import jc
|
||||
result = jc.parse('ethtool', ethtool_command_output)
|
||||
|
||||
Schema:
|
||||
|
||||
{
|
||||
"name": string,
|
||||
"supported_ports": [
|
||||
string
|
||||
],
|
||||
"supported_link_modes": [
|
||||
string
|
||||
],
|
||||
"supported_pause_frame_use": string,
|
||||
"supports_auto_negotiation": boolean,
|
||||
"supported_fec_modes": [
|
||||
string
|
||||
],
|
||||
"advertised_link_modes": [
|
||||
string
|
||||
],
|
||||
"advertised_pause_frame_use": boolean,
|
||||
"advertised_auto_negotiation": boolean,
|
||||
"advertised_fec_modes": [
|
||||
string
|
||||
],
|
||||
"speed": string,
|
||||
"speed_bps": integer,
|
||||
"duplex": string,
|
||||
"auto_negotiation": boolean,
|
||||
"port": string,
|
||||
"phyad": string,
|
||||
"mdi_x": string,
|
||||
"transceiver": string,
|
||||
"supports_wake_on": string,
|
||||
"wake_on": string,
|
||||
"current_message_level": [
|
||||
string
|
||||
],
|
||||
"link_detected": boolean,
|
||||
"identifier": string,
|
||||
"extended_identifier": string,
|
||||
"connector": string,
|
||||
"transceiver_codes": string,
|
||||
"transceiver_type": [
|
||||
string
|
||||
],
|
||||
"encoding": string,
|
||||
"br_nominal": string,
|
||||
"rate_identifier": string,
|
||||
"length_smf_km": string,
|
||||
"length_smf": string,
|
||||
"length_50um": string,
|
||||
"length_62_5um": string,
|
||||
"length_copper": string,
|
||||
"length_om3": string,
|
||||
"passive_cu_cmplnce": string,
|
||||
"vendor_name": string,
|
||||
"vendor_oui": string,
|
||||
"vendor_pn": string,
|
||||
"vendor_rev": string,
|
||||
"option_values": string,
|
||||
"br_margin_max": string,
|
||||
"br_margin_min": string
|
||||
}
|
||||
|
||||
Examples:
|
||||
|
||||
$ ethtool | jc --ethtool -p
|
||||
[]
|
||||
|
||||
$ ethtool | jc --ethtool -p -r
|
||||
[]
|
||||
|
||||
<a id="jc.parsers.ethtool.parse"></a>
|
||||
|
||||
### parse
|
||||
|
||||
```python
|
||||
def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
Source: [`jc/parsers/ethtool.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/ethtool.py)
|
||||
|
||||
Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com)
|
@ -1,12 +1,16 @@
|
||||
"""jc - JSON Convert `ethtool` command output parser
|
||||
|
||||
Supports standard `ethtool` output and the `--module-info` option.
|
||||
|
||||
Usage (cli):
|
||||
|
||||
$ ethtool <interface> | jc --ethtool
|
||||
$ ethtool --module-info <interface> | jc --ethtool
|
||||
|
||||
or
|
||||
|
||||
$ jc ethtool <interface>
|
||||
$ jc ethtool --module-info <interface>
|
||||
|
||||
Usage (module):
|
||||
|
||||
@ -49,7 +53,31 @@ Schema:
|
||||
"current_message_level": [
|
||||
string
|
||||
],
|
||||
"link_detected": boolean
|
||||
"link_detected": boolean,
|
||||
"identifier": string,
|
||||
"extended_identifier": string,
|
||||
"connector": string,
|
||||
"transceiver_codes": string,
|
||||
"transceiver_type": [
|
||||
string
|
||||
],
|
||||
"encoding": string,
|
||||
"br_nominal": string,
|
||||
"rate_identifier": string,
|
||||
"length_smf_km": string,
|
||||
"length_smf": string,
|
||||
"length_50um": string,
|
||||
"length_62_5um": string,
|
||||
"length_copper": string,
|
||||
"length_om3": string,
|
||||
"passive_cu_cmplnce": string,
|
||||
"vendor_name": string,
|
||||
"vendor_oui": string,
|
||||
"vendor_pn": string,
|
||||
"vendor_rev": string,
|
||||
"option_values": string,
|
||||
"br_margin_max": string,
|
||||
"br_margin_min": string
|
||||
}
|
||||
|
||||
Examples:
|
||||
@ -104,6 +132,171 @@ def _process(proc_data: JSONDictType) -> JSONDictType:
|
||||
return proc_data
|
||||
|
||||
|
||||
def _parse_default(data: str) -> JSONDictType:
|
||||
raw_output: Dict = {}
|
||||
supported_ports: List[str] = []
|
||||
supported_link_modes: List[str] = []
|
||||
supported_fec_modes: List[str] = []
|
||||
advertised_link_modes: List[str] = []
|
||||
advertised_fec_modes: List[str] = []
|
||||
current_message_level: List[str] = []
|
||||
mode: str = '' # supported_link_modes, supported_fec_modes, advertised_link_modes,
|
||||
# advertised_fec_modes, current_message_level
|
||||
|
||||
for line in filter(None, data.splitlines()):
|
||||
|
||||
if line.startswith('Settings for '):
|
||||
raw_output['name'] = line.split()[2][:-1]
|
||||
continue
|
||||
|
||||
data_line = line.replace('\t', ' ')
|
||||
if not data_line.startswith(' '): # 9 spaces
|
||||
mode = ''
|
||||
|
||||
if 'Supported ports:' in line:
|
||||
_, val = line.split(':', maxsplit=1)
|
||||
val = val.strip()[1:-1]
|
||||
val_list = val.split()
|
||||
supported_ports.extend(val_list)
|
||||
continue
|
||||
|
||||
if 'Supported link modes:' in line and 'Not reported' not in line:
|
||||
_, val = line.split(':', maxsplit=1)
|
||||
val = val.strip()
|
||||
val_list = val.split()
|
||||
supported_link_modes.extend(val_list)
|
||||
mode = 'supported_link_modes'
|
||||
continue
|
||||
|
||||
if 'Supported FEC modes:' in line and 'Not reported' not in line:
|
||||
_, val = line.split(':', maxsplit=1)
|
||||
val = val.strip()
|
||||
val_list = val.split()
|
||||
supported_fec_modes.extend(val_list)
|
||||
mode = 'supported_fec_modes'
|
||||
continue
|
||||
|
||||
if 'Advertised link modes:' in line and 'Not reported' not in line:
|
||||
_, val = line.split(':', maxsplit=1)
|
||||
val = val.strip()
|
||||
val_list = val.split()
|
||||
advertised_link_modes.extend(val_list)
|
||||
mode = 'advertised_link_modes'
|
||||
continue
|
||||
|
||||
if 'Advertised FEC modes:' in line and 'Not reported' not in line:
|
||||
_, val = line.split(':', maxsplit=1)
|
||||
val = val.strip()
|
||||
val_list = val.split()
|
||||
advertised_fec_modes.extend(val_list)
|
||||
mode = 'advertised_fec_modes'
|
||||
continue
|
||||
|
||||
if 'Current message level:' in line:
|
||||
_, val = line.split(':', maxsplit=1)
|
||||
current_message_level.append(val.strip())
|
||||
mode = 'current_message_level'
|
||||
continue
|
||||
|
||||
if mode == 'supported_link_modes':
|
||||
val = line.strip()
|
||||
val_list = val.split()
|
||||
supported_link_modes.extend(val_list)
|
||||
continue
|
||||
|
||||
if mode == 'supported_fec_modes':
|
||||
val = line.strip()
|
||||
val_list = val.split()
|
||||
supported_fec_modes.extend(val_list)
|
||||
continue
|
||||
|
||||
if mode == 'advertised_link_modes':
|
||||
val = line.strip()
|
||||
val_list = val.split()
|
||||
advertised_link_modes.extend(val_list)
|
||||
continue
|
||||
|
||||
if mode == 'advertised_fec_modes':
|
||||
val = line.strip()
|
||||
val_list = val.split()
|
||||
advertised_fec_modes.extend(val_list)
|
||||
continue
|
||||
|
||||
if mode == 'current_message_level':
|
||||
current_message_level.append(line.strip())
|
||||
continue
|
||||
|
||||
key, val = line.split(':', maxsplit=1)
|
||||
key = jc.utils.normalize_key(key)
|
||||
val = val.strip()
|
||||
raw_output[key] = val
|
||||
|
||||
if supported_ports:
|
||||
raw_output['supported_ports'] = supported_ports
|
||||
if supported_link_modes:
|
||||
raw_output['supported_link_modes'] = supported_link_modes
|
||||
if supported_fec_modes:
|
||||
raw_output['supported_fec_modes'] = supported_fec_modes
|
||||
if advertised_link_modes:
|
||||
raw_output['advertised_link_modes'] = advertised_link_modes
|
||||
if advertised_fec_modes:
|
||||
raw_output['advertised_fec_modes'] = advertised_fec_modes
|
||||
if current_message_level:
|
||||
raw_output['current_message_level'] = current_message_level
|
||||
|
||||
return raw_output
|
||||
|
||||
|
||||
def _parse_module_info(data: str) -> JSONDictType:
|
||||
raw_output: Dict = {}
|
||||
previous_key: str = ''
|
||||
multi_value: List[str] = []
|
||||
|
||||
for line in filter(None, data.splitlines()):
|
||||
key, val = line.strip().split(':', maxsplit=1)
|
||||
key = jc.utils.normalize_key(key)
|
||||
val = val.strip()
|
||||
|
||||
if key == previous_key:
|
||||
multi_value.append(val)
|
||||
continue
|
||||
|
||||
else:
|
||||
if len(multi_value) > 1:
|
||||
raw_output[previous_key] = multi_value
|
||||
multi_value = []
|
||||
multi_value.append(val)
|
||||
previous_key = key
|
||||
continue
|
||||
|
||||
elif len(multi_value) == 1:
|
||||
raw_output[previous_key] = multi_value[0]
|
||||
multi_value = []
|
||||
multi_value.append(val)
|
||||
previous_key = key
|
||||
continue
|
||||
|
||||
else:
|
||||
raw_output[previous_key] = ''
|
||||
multi_value.append(val)
|
||||
previous_key = key
|
||||
continue
|
||||
|
||||
if len(multi_value) > 1:
|
||||
raw_output[key] = multi_value
|
||||
|
||||
elif len(multi_value) == 1:
|
||||
raw_output[key] = multi_value[0]
|
||||
|
||||
else:
|
||||
raw_output[key] = ''
|
||||
|
||||
if '' in raw_output:
|
||||
del raw_output['']
|
||||
|
||||
return raw_output
|
||||
|
||||
|
||||
def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType:
|
||||
"""
|
||||
Main text parsing function
|
||||
@ -122,116 +315,13 @@ def parse(data: str, raw: bool = False, quiet: bool = False) -> JSONDictType:
|
||||
jc.utils.input_type_check(data)
|
||||
|
||||
raw_output: Dict = {}
|
||||
supported_ports: List[str] = []
|
||||
supported_link_modes: List[str] = []
|
||||
supported_fec_modes: List[str] = []
|
||||
advertised_link_modes: List[str] = []
|
||||
advertised_fec_modes: List[str] = []
|
||||
current_message_level: List[str] = []
|
||||
mode: str = '' # supported_link_modes, supported_fec_modes, advertised_link_modes,
|
||||
# advertised_fec_modes, current_message_level
|
||||
|
||||
if jc.utils.has_data(data):
|
||||
|
||||
for line in filter(None, data.splitlines()):
|
||||
if data.strip().startswith('Settings for '):
|
||||
raw_output = _parse_default(data)
|
||||
|
||||
if line.startswith('Settings for '):
|
||||
raw_output['name'] = line.split()[2][:-1]
|
||||
continue
|
||||
|
||||
data_line = line.replace('\t', ' ')
|
||||
if not data_line.startswith(' '): # 9 spaces
|
||||
mode = ''
|
||||
|
||||
if 'Supported ports:' in line:
|
||||
_, val = line.split(':', maxsplit=1)
|
||||
val = val.strip()[1:-1]
|
||||
val_list = val.split()
|
||||
supported_ports.extend(val_list)
|
||||
continue
|
||||
|
||||
if 'Supported link modes:' in line and 'Not reported' not in line:
|
||||
_, val = line.split(':', maxsplit=1)
|
||||
val = val.strip()
|
||||
val_list = val.split()
|
||||
supported_link_modes.extend(val_list)
|
||||
mode = 'supported_link_modes'
|
||||
continue
|
||||
|
||||
if 'Supported FEC modes:' in line and 'Not reported' not in line:
|
||||
_, val = line.split(':', maxsplit=1)
|
||||
val = val.strip()
|
||||
val_list = val.split()
|
||||
supported_fec_modes.extend(val_list)
|
||||
mode = 'supported_fec_modes'
|
||||
continue
|
||||
|
||||
if 'Advertised link modes:' in line and 'Not reported' not in line:
|
||||
_, val = line.split(':', maxsplit=1)
|
||||
val = val.strip()
|
||||
val_list = val.split()
|
||||
advertised_link_modes.extend(val_list)
|
||||
mode = 'advertised_link_modes'
|
||||
continue
|
||||
|
||||
if 'Advertised FEC modes:' in line and 'Not reported' not in line:
|
||||
_, val = line.split(':', maxsplit=1)
|
||||
val = val.strip()
|
||||
val_list = val.split()
|
||||
advertised_fec_modes.extend(val_list)
|
||||
mode = 'advertised_fec_modes'
|
||||
continue
|
||||
|
||||
if 'Current message level:' in line:
|
||||
_, val = line.split(':', maxsplit=1)
|
||||
current_message_level.append(val.strip())
|
||||
mode = 'current_message_level'
|
||||
continue
|
||||
|
||||
if mode == 'supported_link_modes':
|
||||
val = line.strip()
|
||||
val_list = val.split()
|
||||
supported_link_modes.extend(val_list)
|
||||
continue
|
||||
|
||||
if mode == 'supported_fec_modes':
|
||||
val = line.strip()
|
||||
val_list = val.split()
|
||||
supported_fec_modes.extend(val_list)
|
||||
continue
|
||||
|
||||
if mode == 'advertised_link_modes':
|
||||
val = line.strip()
|
||||
val_list = val.split()
|
||||
advertised_link_modes.extend(val_list)
|
||||
continue
|
||||
|
||||
if mode == 'advertised_fec_modes':
|
||||
val = line.strip()
|
||||
val_list = val.split()
|
||||
advertised_fec_modes.extend(val_list)
|
||||
continue
|
||||
|
||||
if mode == 'current_message_level':
|
||||
current_message_level.append(line.strip())
|
||||
continue
|
||||
|
||||
key, val = line.split(':', maxsplit=1)
|
||||
key = jc.utils.normalize_key(key)
|
||||
val = val.strip()
|
||||
raw_output[key] = val
|
||||
|
||||
if supported_ports:
|
||||
raw_output['supported_ports'] = supported_ports
|
||||
if supported_link_modes:
|
||||
raw_output['supported_link_modes'] = supported_link_modes
|
||||
if supported_fec_modes:
|
||||
raw_output['supported_fec_modes'] = supported_fec_modes
|
||||
if advertised_link_modes:
|
||||
raw_output['advertised_link_modes'] = advertised_link_modes
|
||||
if advertised_fec_modes:
|
||||
raw_output['advertised_fec_modes'] = advertised_fec_modes
|
||||
if current_message_level:
|
||||
raw_output['current_message_level'] = current_message_level
|
||||
elif data.strip().startswith('Identifier '):
|
||||
raw_output = _parse_module_info(data)
|
||||
|
||||
return raw_output if raw else _process(raw_output)
|
||||
|
12
man/jc.1
12
man/jc.1
@ -1,4 +1,4 @@
|
||||
.TH jc 1 2024-02-28 1.25.2 "JSON Convert"
|
||||
.TH jc 1 2024-03-01 1.25.2 "JSON Convert"
|
||||
.SH NAME
|
||||
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types,
|
||||
and strings
|
||||
@ -57,6 +57,11 @@ Parsers:
|
||||
\fB--apt-cache-show\fP
|
||||
`apt-cache show` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--apt-get-sqq\fP
|
||||
`apt-get -sqq` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--arp\fP
|
||||
@ -207,6 +212,11 @@ Email Address string parser
|
||||
\fB--env\fP
|
||||
`env` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--ethtool\fP
|
||||
`ethtool` command parser
|
||||
|
||||
.TP
|
||||
.B
|
||||
\fB--file\fP
|
||||
|
Reference in New Issue
Block a user