From ecd4ed043e05e874868267914820a1e06ad087ad Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Wed, 20 Oct 2021 00:37:46 +0100 Subject: [PATCH] Add list_json() As we now have valid CSV, pipe that into a jq filter to generate JSON. https://stackoverflow.com/a/67359273 --- quickget | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/quickget b/quickget index 52917a5..331f45e 100755 --- a/quickget +++ b/quickget @@ -59,7 +59,12 @@ function validate_release() { fi } -function list_all() { +function list_json() { + # Reference: https://stackoverflow.com/a/67359273 + list_csv | jq -R 'split(",") as $h|reduce inputs as $in ([]; . += [$in|split(",")|. as $a|reduce range(0,length) as $i ({};.[$h[$i]]=$a[$i])])' + exit 0 +} + function list_csv() { local DISPLAY_NAME local FUNC @@ -823,6 +828,8 @@ if [ -n "${1}" ]; then OS="${1,,}" if [ "${OS}" == "list" ] || [ "${OS}" == "list_csv" ]; then list_csv + elif [ "${OS}" == "list_json" ]; then + list_json fi else echo "ERROR! You must specify an operating system:"