Skip to content

Commit

Permalink
more changes
Browse files Browse the repository at this point in the history
Signed-off-by: Leandro Mendes <[email protected]>
  • Loading branch information
theflockers committed Aug 28, 2023
1 parent f00f59d commit 2953889
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions utils/update-paths
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,18 @@ for(( p=0; p<pathsLength; p++)); do
replacementsLength=$(jq '.replacements | length' <<< "${path}")
for(( r=0; r<replacementsLength; r++ )); do

replacement=$(jq -cr ".replacements[${r}]" <<< "${path}")
replacement=$(jq -cr ".replacements[${r}].replacement" <<< "${path}" |jq -R )
if grep -q '{{.*}}' <<< "${replacement}"; then
# get the yq expression and use xargs to remove the trailling whitespaces
yqExp=$(sed 's|.*{{\(.*\)}}.*|\1|' <<< "${replacement}"| xargs)
yqExp=$(sed 's|.*{{\(.*\)}}.*|\1|' <<< "${replacement}")

# execute the yq expression and replace the "replacement string" with the result
yqResult=$(yq -oy -r "${yqExp}" "${FILE}")
newReplacement=$(sed "s|{{.*}}|"${yqResult}"|g" <<< "${replacement}")

# appends to the newReplacements array
newReplacements=$(jq -cr ".replacements += [${newReplacement}]" <<< "${newReplacements}")
else
newReplacements=$(jq -cr ".replacements += [${replacement}]" <<< "${newReplacements}")
PATHS=$(jq -cr ".[${p}].replacements[$r].replacement = ${newReplacement}" <<< "${PATHS}")
fi
done
# merge the two hashes and append to the newPaths array
merged=$(jq -cr -s add <<< "${newPath} ${newReplacements}")
newPaths=$(jq -cr ".paths += [ ${merged} ]" <<< "${newPaths}")
done
jq -cr '.paths' <<< "${newPaths}"
echo "${PATHS}"

0 comments on commit 2953889

Please sign in to comment.