diff options
author | Singustromo <singustromo@disroot.org> | 2023-11-05 13:46:50 +0100 |
---|---|---|
committer | Singustromo <singustromo@disroot.org> | 2023-11-05 13:46:50 +0100 |
commit | 6e6704d9b345bed0a0ab7c784cc7da2bce8809f7 (patch) | |
tree | 064a66b8af16b749264e1d65d1cb5a8a2e13c61a | |
parent | 89f4353ed7e9085f0f535225b6b45fc971cf92d7 (diff) | |
download | radio-sh-6e6704d9b345bed0a0ab7c784cc7da2bce8809f7.tar.gz radio-sh-6e6704d9b345bed0a0ab7c784cc7da2bce8809f7.zip |
streamlined Config:get()
-rwxr-xr-x | radio | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/radio b/radio index 33ab4d3..4ea8316 100755 --- a/radio +++ b/radio @@ -54,7 +54,8 @@ _menu_items="" # current menu # Prints debug messages to stderr # depends: $_debug Sys:log() { - { [ "$_debug" == '1' ] && [ -n "$*" ]; } || { true; return; } + { [ "$_debug" == '1' ] && [ -n "$*" ]; } || return + local line_no="${BASH_LINENO[0]}" i=2 local out="(${FUNCNAME[1]}:_LINE_) [caller: " @@ -396,15 +397,14 @@ Config:set() { } # prints the corresponding option values from the json configuration -# If multiple (separated by space) are given as parameters, -# they are separated by a new line. +# When multiple options (separated by space) are given as parameters, +# their corresponding values are separated by a new line. # Valid options are the ones in the associative array (beginning of script) -# If requested option is invalid, it returns 'nil' in respective line. +# If requested option is invalid, it returns 'null' in respective line. # Depends: $_configuration Config:get() { local options="$*" - local return_values jq_query jq_result - local option_values=() + local jq_query jq_result Sys:log "Parameters:\n$options" (( $# )) || return @@ -412,16 +412,9 @@ Config:get() { jq_result="$(printf "%s" "$_configuration" \ | jq -r '.option | '"$jq_query")" # jq returns null for unset options + Sys:log "jq_result:\n${jq_result//$'\n'/ }" - local i=0 - for result in $jq_result; do - # assign result to an empty field - option_values[$i]="$result" - (( i++ )) - done - - return_values="${option_values[*]}" # has to be separate - printf "%b\n" "${return_values// /\\n}" + printf "%b\n" "$jq_result" } # Returns all options with respective value |