From 75d06ef96742ff04f6ff1304e366784312a41c70 Mon Sep 17 00:00:00 2001 From: Sebastian <379651+czarly@users.noreply.github.com> Date: Tue, 24 Sep 2024 08:28:11 +0200 Subject: [PATCH] init --- network-to-config.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/network-to-config.sh b/network-to-config.sh index 2e475c01..ab3f795e 100755 --- a/network-to-config.sh +++ b/network-to-config.sh @@ -9,7 +9,22 @@ fi BASEPATH="$(dirname "$0")" JSON_FILE="$BASEPATH/reference-rpc-endpoint.json" -shift -# Extract values under 'default' or 'archive' attributes for given keys -jq --argfile input "$JSON_FILE" '. as $in | ($IN.input | select(has("default")) | .default[]) + ($IN.input | select(has("archive")) | .archive[])' "$@" +# Function to extract values for a given key +extract_values() { + local key=$1 + cat "$JSON_FILE" | jq -r --arg key "$key" '.[$key] | .default? // .archive? // [] | .[]' +} + +# Initialize an empty result string +result="" + +# Iterate over each key passed as a parameter +for key in "$@"; do + # Append the values from the key to the result string + values=$(extract_values "$key") + result="$result $values" +done + +# Trim and display the result +echo $result | xargs