diff --git a/CHANGELOG b/CHANGELOG index 2d59e8e7..64b8dcf1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,7 +13,7 @@ jc changelog - Add source link to online parser documentation - Refactor parser aliases for `kv`, `pkg_index_deb`, `lsb_release`, and `os-release` - TODO: Add `line_slice` function to `utils.py` -- TODO: Update copyright date +- Update copyright date 20231216 v1.24.0 - Add `debconf-show` command parser diff --git a/README.md b/README.md index c8739893..7cad0239 100644 --- a/README.md +++ b/README.md @@ -331,6 +331,7 @@ option. | `-p` | `--pretty` | Pretty format the JSON output | | `-q` | `--quiet` | Quiet mode. Suppresses parser warning messages (use `-qq` to ignore streaming parser errors) | | `-r` | `--raw` | Raw output. Provides more literal output, typically with string values and no additional semantic processing | +| `-s` | `--slurp` | Slurp multiple lines into an array. (use `-hhh` to find compatible parsers) | | `-u` | `--unbuffer` | Unbuffer output | | `-v` | `--version` | Version information | | `-y` | `--yaml-out` | YAML output | @@ -1314,4 +1315,4 @@ cat istio.yaml | jc -p --yaml ] ``` -© 2019-2023 Kelly Brazil \ No newline at end of file +© 2019-2024 Kelly Brazil \ No newline at end of file diff --git a/completions/jc_bash_completion.sh b/completions/jc_bash_completion.sh index 6bdd9614..c3ee82bf 100644 --- a/completions/jc_bash_completion.sh +++ b/completions/jc_bash_completion.sh @@ -5,7 +5,7 @@ _jc() jc_commands=(acpi airport arp blkid bluetoothctl cbt certbot chage cksum crontab date debconf-show df dig dmidecode dpkg du 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 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 --arp --asciitable --asciitable-m --blkid --bluetoothctl --cbt --cef --cef-s --certbot --chage --cksum --clf --clf-s --crontab --crontab-u --csv --csv-s --date --datetime-iso --debconf-show --df --dig --dir --dmidecode --dpkg-l --du --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 --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 --netstat --nmcli --nsd-control --ntpq --openvpn --os-prober --os-release --passwd --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 --unbuffer -u --yaml-out -y) + 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) jc_help_options=(--help -h) diff --git a/completions/jc_zsh_completion.sh b/completions/jc_zsh_completion.sh index 48d675b4..010a8311 100644 --- a/completions/jc_zsh_completion.sh +++ b/completions/jc_zsh_completion.sh @@ -329,7 +329,7 @@ _jc() { '--zpool-iostat:`zpool iostat` command parser' '--zpool-status:`zpool status` command parser' ) - jc_options=(--force-color -C --debug -d --monochrome -m --meta-out -M --pretty -p --quiet -q --raw -r --unbuffer -u --yaml-out -y) + 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_options_describe=( '--force-color:force color output (overrides -m)' '-C:force color output (overrides -m)' @@ -345,6 +345,8 @@ _jc() { '-q:suppress warnings (double to ignore streaming errors)' '--raw:raw output' '-r:raw output' + '--slurp:slurp multiple lines into an array' + '-s:slurp multiple lines into an array' '--unbuffer:unbuffer output' '-u:unbuffer output' '--yaml-out:YAML output' diff --git a/docgen.sh b/docgen.sh index 4391f7bc..a403c627 100755 --- a/docgen.sh +++ b/docgen.sh @@ -132,6 +132,12 @@ for parser in "${parsers[@]}"; do echo >> ../docs/parsers/"${parser_name}".md echo "Source: [\`jc/parsers/${parser_name}.py\`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/${parser_name}.py)" >> ../docs/parsers/"${parser_name}".md echo >> ../docs/parsers/"${parser_name}".md + + if $(jq -e '.tags | contains(["slurpable"])' <<< "$parser"); then + echo "This parser can be used with the \`--slurp\` command-line option." >> ../docs/parsers/"${parser_name}".md + echo >> ../docs/parsers/"${parser_name}".md + fi + echo "Version ${version} by ${author} (${author_email})" >> ../docs/parsers/"${parser_name}".md echo "+++ ${parser_name} docs complete" fi diff --git a/docs/lib.md b/docs/lib.md index c1a2b488..5b9bb443 100644 --- a/docs/lib.md +++ b/docs/lib.md @@ -6,6 +6,7 @@ * [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) + * [slurpable\_parser\_mod\_list](#jc.lib.slurpable_parser_mod_list) * [parser\_info](#jc.lib.parser_info) * [all\_parser\_info](#jc.lib.all_parser_info) * [get\_help](#jc.lib.get_help) @@ -156,6 +157,18 @@ def streaming_parser_mod_list(show_hidden: bool = False, Returns a list of streaming parser module names. This function is a subset of `parser_mod_list()`. + + +### slurpable\_parser\_mod\_list + +```python +def slurpable_parser_mod_list(show_hidden: bool = False, + show_deprecated: bool = False) -> List[str] +``` + +Returns a list of slurpable parser module names. This function is a +subset of `parser_mod_list()`. + ### parser\_info diff --git a/docs/parsers/date.md b/docs/parsers/date.md index 9e877cae..81469354 100644 --- a/docs/parsers/date.md +++ b/docs/parsers/date.md @@ -102,4 +102,6 @@ Compatibility: linux, darwin, freebsd Source: [`jc/parsers/date.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/date.py) -Version 2.5 by Kelly Brazil (kellyjonbrazil@gmail.com) +This parser can be used with the `--slurp` command-line option. + +Version 2.6 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/datetime_iso.md b/docs/parsers/datetime_iso.md index 09197274..c8a8651a 100644 --- a/docs/parsers/datetime_iso.md +++ b/docs/parsers/datetime_iso.md @@ -90,4 +90,6 @@ Compatibility: linux, aix, freebsd, darwin, win32, cygwin Source: [`jc/parsers/datetime_iso.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/datetime_iso.py) -Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) +This parser can be used with the `--slurp` command-line option. + +Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/email_address.md b/docs/parsers/email_address.md index a7dbbd87..ecb8765d 100644 --- a/docs/parsers/email_address.md +++ b/docs/parsers/email_address.md @@ -66,4 +66,6 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd Source: [`jc/parsers/email_address.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/email_address.py) -Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) +This parser can be used with the `--slurp` command-line option. + +Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/ip_address.md b/docs/parsers/ip_address.md index 7dad584d..7b1fa416 100644 --- a/docs/parsers/ip_address.md +++ b/docs/parsers/ip_address.md @@ -554,4 +554,6 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd Source: [`jc/parsers/ip_address.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/ip_address.py) -Version 1.3 by Kelly Brazil (kellyjonbrazil@gmail.com) +This parser can be used with the `--slurp` command-line option. + +Version 1.4 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/jwt.md b/docs/parsers/jwt.md index f39354e9..f8431d46 100644 --- a/docs/parsers/jwt.md +++ b/docs/parsers/jwt.md @@ -72,4 +72,6 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd Source: [`jc/parsers/jwt.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/jwt.py) -Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) +This parser can be used with the `--slurp` command-line option. + +Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/semver.md b/docs/parsers/semver.md index 07b5e882..57615dc3 100644 --- a/docs/parsers/semver.md +++ b/docs/parsers/semver.md @@ -76,4 +76,6 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd Source: [`jc/parsers/semver.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/semver.py) -Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) +This parser can be used with the `--slurp` command-line option. + +Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/timestamp.md b/docs/parsers/timestamp.md index b5df2b13..9965abfa 100644 --- a/docs/parsers/timestamp.md +++ b/docs/parsers/timestamp.md @@ -121,4 +121,6 @@ Compatibility: linux, aix, freebsd, darwin, win32, cygwin Source: [`jc/parsers/timestamp.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/timestamp.py) -Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) +This parser can be used with the `--slurp` command-line option. + +Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/url.md b/docs/parsers/url.md index 69921807..8a4d1096 100644 --- a/docs/parsers/url.md +++ b/docs/parsers/url.md @@ -259,4 +259,6 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd Source: [`jc/parsers/url.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/url.py) -Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) +This parser can be used with the `--slurp` command-line option. + +Version 1.2 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/docs/parsers/ver.md b/docs/parsers/ver.md index fc5422d8..b1948934 100644 --- a/docs/parsers/ver.md +++ b/docs/parsers/ver.md @@ -111,4 +111,6 @@ Compatibility: linux, darwin, cygwin, win32, aix, freebsd Source: [`jc/parsers/ver.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/ver.py) -Version 1.0 by Kelly Brazil (kellyjonbrazil@gmail.com) +This parser can be used with the `--slurp` command-line option. + +Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/jc/cli.py b/jc/cli.py index a66b8b5b..aa0d68af 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -55,7 +55,7 @@ class info(): author: str = 'Kelly Brazil' author_email: str = 'kellyjonbrazil@gmail.com' website: str = 'https://github.com/kellyjonbrazil/jc' - copyright: str = '© 2019-2023 Kelly Brazil' + copyright: str = '© 2019-2024 Kelly Brazil' license: str = 'MIT License' @@ -283,6 +283,7 @@ class JcCli(): 'standard_parser_count': len(standard_parser_mod_list(show_hidden=True, show_deprecated=True)), 'streaming_parser_count': len(streaming_parser_mod_list(show_hidden=True, show_deprecated=True)), 'plugin_parser_count': len(plugin_parser_mod_list(show_hidden=True, show_deprecated=True)), + 'slurpable_parser_count': len(slurpable_parser_mod_list(show_hidden=True, show_deprecated=True)), 'parsers': all_parser_info(show_hidden=True, show_deprecated=True) } @@ -315,9 +316,15 @@ class JcCli(): version: str = p_info.get('version', 'unknown') author: str = p_info.get('author', 'unknown') author_email: str = p_info.get('author_email', 'unknown') + + slurpy = '' + if 'slurpable' in p_info.get('tags', []): + slurpy = 'This parser can be used with the --slurp command-line option.\n\n' + doc_text: str = \ - f'{docs}\n'\ - f'Compatibility: {compatible}\n\n'\ + f'{docs}\n' \ + f'Compatibility: {compatible}\n\n' \ + f'{slurpy}' \ f'Version {version} by {author} ({author_email})\n' utils._safe_pager(doc_text) @@ -770,7 +777,6 @@ class JcCli(): if self.parser_module: if self.slurp: self.create_slurp_output() - else: self.create_normal_output() diff --git a/jc/lib.py b/jc/lib.py index 3fbf8e45..b4480780 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -9,7 +9,7 @@ from .jc_types import ParserInfoType, JSONDictType from jc import appdirs -__version__ = '1.24.0' +__version__ = '1.24.1' parsers: List[str] = [ 'acpi', diff --git a/man/jc.1 b/man/jc.1 index 493ee380..89aeca17 100644 --- a/man/jc.1 +++ b/man/jc.1 @@ -1,4 +1,4 @@ -.TH jc 1 2023-12-22 1.24.0 "JSON Convert" +.TH jc 1 2024-01-03 1.24.1 "JSON Convert" .SH NAME \fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types, and strings @@ -1142,6 +1142,10 @@ Raw output. Provides more literal output, typically with string values and no additional semantic processing .TP .B +\fB-s\fP, \fB--slurp\fP +Slurp multiple lines into an array. (use \fB-hhh\fP` to find compatible parsers) +.TP +.B \fB-u\fP, \fB--unbuffer\fP Unbuffer output (useful for slow streaming data with streaming parsers) .TP @@ -1510,6 +1514,6 @@ Kelly Brazil (kellyjonbrazil@gmail.com) https://github.com/kellyjonbrazil/jc .SH COPYRIGHT -Copyright (c) 2019-2023 Kelly Brazil +Copyright (c) 2019-2024 Kelly Brazil License: MIT License \ No newline at end of file diff --git a/setup.py b/setup.py index 0eaa64f8..13559f14 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open('README.md', 'r') as f: setuptools.setup( name='jc', - version='1.24.0', + version='1.24.1', author='Kelly Brazil', author_email='kellyjonbrazil@gmail.com', description='Converts the output of popular command-line tools and file-types to JSON.', diff --git a/templates/manpage_template b/templates/manpage_template index 26e8a0c2..9cb837ae 100644 --- a/templates/manpage_template +++ b/templates/manpage_template @@ -92,6 +92,10 @@ Raw output. Provides more literal output, typically with string values and no additional semantic processing .TP .B +\fB-s\fP, \fB--slurp\fP +Slurp multiple lines into an array. (use \fB-hhh\fP` to find compatible parsers) +.TP +.B \fB-u\fP, \fB--unbuffer\fP Unbuffer output (useful for slow streaming data with streaming parsers) .TP diff --git a/templates/readme_template b/templates/readme_template index eb38c0a6..5dbef813 100644 --- a/templates/readme_template +++ b/templates/readme_template @@ -172,6 +172,7 @@ option. | `-p` | `--pretty` | Pretty format the JSON output | | `-q` | `--quiet` | Quiet mode. Suppresses parser warning messages (use `-qq` to ignore streaming parser errors) | | `-r` | `--raw` | Raw output. Provides more literal output, typically with string values and no additional semantic processing | +| `-s` | `--slurp` | Slurp multiple lines into an array. (use `-hhh` to find compatible parsers) | | `-u` | `--unbuffer` | Unbuffer output | | `-v` | `--version` | Version information | | `-y` | `--yaml-out` | YAML output |