Skip to content

Commit

Permalink
cleaning up the code
Browse files Browse the repository at this point in the history
Signed-off-by: Leandro Mendes <[email protected]>
  • Loading branch information
theflockers committed Aug 29, 2023
1 parent 2953889 commit a38613e
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions utils/update-paths
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,21 @@ if [ -z "${PATHS}" ] || [ -z "${FILE}" ]; then
exit
fi

newPaths='{"paths": []}'
pathsLength=$(jq -cr '. |length' <<< "${PATHS}")
for(( p=0; p<pathsLength; p++)); do

path=$(jq ".[${p}]" <<< "${PATHS}")
newPath=$(jq '{"path": .path}' <<< "${path}")

newReplacements='{"replacements": []}'
replacementsLength=$(jq '.replacements | length' <<< "${path}")
for(( r=0; r<replacementsLength; r++ )); do

replacement=$(jq -cr ".replacements[${r}].replacement" <<< "${path}" |jq -R )
replacement=$(jq -cr ".replacements[${r}].replacement" <<< "${path}")
if grep -q '{{.*}}' <<< "${replacement}"; then
# get the yq expression and use xargs to remove the trailling whitespaces
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
PATHS=$(jq -cr ".[${p}].replacements[$r].replacement = ${newReplacement}" <<< "${PATHS}")
PATHS=$(jq -cr ".[${p}].replacements[$r].replacement = \"${newReplacement}\"" <<< "${PATHS}")
fi
done
done
Expand Down

0 comments on commit a38613e

Please sign in to comment.