]> git.vanrenterghem.biz Git - elgato-keylight-script.git/blobdiff - keylights.sh
Co-authored-by: JonssonViktor <JonssonViktor@users.noreply.github.com>
[elgato-keylight-script.git] / keylights.sh
index 4a1a1df0cb7b363c183dce7965e848b64389c121..1dab5117c592013987618a3dc38ace9061065da6 100755 (executable)
@@ -157,10 +157,10 @@ output() {
     json) print_json "$lights_json" ;;
     simple) print_json "$simple_json" ;;
     flat) print_json "$flat_json" ;;
-    table) print_structured "$simple_json" '@tsv' ;;
-    csv) print_structured "$simple_json" '@csv' ;;
-    pair) print_structured "$simple_json" 'pairs' ;;
-    html) print_html "$simple_json" ;;
+    table) print_structured '@tsv' ;;
+    csv) print_structured '@csv' ;;
+    pair) print_structured 'pairs' ;;
+    html) print_html ;;
     -?*) die "Unknown output format (-f/--format): $format" ;;
     esac
 }
@@ -178,25 +178,25 @@ print_json() {
 }
 
 print_structured() {
-    pp=${3-$pretty}
+    pp=${2-$pretty}
     # Handle csv and table printing
-    query="(.[0] | keys_unsorted | map(ascii_upcase)), (.[] | [.[]])|${2-@csv}"
+    query="(.[0] | keys_unsorted | map(ascii_upcase)), (.[] | [.[]])|${1-@csv}"
 
     # Handle printing as key value pairs
-    if [[ ${2} == 'pairs' ]]; then
+    if [[ ${1} == 'pairs' ]]; then
         query='.[] | "--------------",(to_entries[] | [.key, "=", .value] | @tsv)'
     fi
 
     # Manage pretty printing
     if [[ $pp -eq 1 ]]; then
-        echo "${1-}" | jq --raw-output "$query" | column -t -s$'\t' | sed -e 's/"//g'
+        echo "${simple_json}" | jq --raw-output "$query" | column -t -s$'\t' | sed -e 's/"//g'
     else
-        echo "${1-}" | jq -r "$query"
+        echo "${simple_json}" | jq -r "$query"
     fi
 }
 
 print_html() {
-    data=$(print_structured "$1" '@csv' 1)
+    data=$(print_structured '@csv' 1)
 
     html="
     <table>
@@ -212,7 +212,7 @@ print_html() {
         done <<<"${data}"
     )
     </table>"
-    echo "$html" >test.html
+    echo "$html"
 }
 
 set_state() {