Skip to content

Commit

Permalink
chore: Add get_json_array bash function for migration to jq
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpinder committed Nov 25, 2024
1 parent d9caf26 commit 20550f2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scripts/exports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ get_yaml_array() {
readarray -t arr < <(echo "$module_config" | yq -I=0 "$jq_query")
}

# Function to retrieve module configs and populate an array
# Arguments:
# 1. Variable name to store result
# 2. jq query
# 3. Module config content
get_json_array() {
local -n arr=$1
local jq_query=$2
local module_config=$3

if [[ -z $jq_query || -z $module_config ]]; then
echo "Usage: get_json_array VARIABLE_TO_STORE_RESULTS JQ_QUERY MODULE_CONFIG" >&2
return 1
fi

readarray -t arr < <(echo "$module_config" | jq "$jq_query")

This comment has been minimized.

Copy link
@fiftydinar

fiftydinar Nov 25, 2024

Contributor

jq -r might be better instead, as it ignores JSON quotes

}

color_string() {
local string="$1"
local color_code="$2"
Expand Down

0 comments on commit 20550f2

Please sign in to comment.