From e50cc8320364c69e3fb2c01ff3ade5fbee585183 Mon Sep 17 00:00:00 2001 From: Leandro Mendes Date: Thu, 24 Aug 2023 15:32:15 +0200 Subject: [PATCH] fixes Signed-off-by: Leandro Mendes --- utils/update-paths | 59 ++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/utils/update-paths b/utils/update-paths index 96fcb20..c0b23b8 100755 --- a/utils/update-paths +++ b/utils/update-paths @@ -2,23 +2,23 @@ # # script: update-paths # -# description: This script searches for "${{ }}" enclosed yq expression in fileUpdates paths then +# description: This script searches for "{{ }}" enclosed yq expression in fileUpdates paths then # executes and replaces it with its result # # parameters: # -# -p, --paths Json String containing fileUpdates paths with optional yq expression(s) enclosed by "${{ }}" +# -p, --paths Json String containing fileUpdates paths with optional yq expression(s) enclosed by "{{ }}" # The `paths` json string should be properly quoted -# Example: --paths="[{\"path\":\"foo.yaml\",\"replacements\":[{\"key\":\"bar\",\"replacement\":\"\${{'.components[0].containerImage'}}\"}]}]" +# Example: --paths='[{"path":"foo.yaml","replacements":[{"key":"bar","replacement":"{{ .components[0]| .containerImage }}"}]}]' # # -f, --file: Path to the mapping_snapshots.json file # print_help(){ - echo -e "$0 [ -p, --paths ] PATHS [ -f, --file ] FILE\n - \t-p, --paths\tJson String containing fileUpdates paths with optional yq expression(s) enclosed by \"\${{ }}\" - \t\t\tThe \`paths\` json string should be properly escaped/quoted - \t\t\tExample: --paths=\"[{\\\"path\\\":\\\"foo.yaml\\\",\\\"replacements\\\":[{\\\"key\\\":\\\"bar\\\",\\\"replacement\\\":\\\"\\\${{'.components[0].containerImage'}}\\\"}]}]\"\n - \t-f, --file\tPath to mapping_snapshots.json file\n" + echo -e "$0 [ -p, --paths ] PATHS [ -f, --file ] FILE\n" + echo -e "\t-p, --paths\tJson String containing fileUpdates paths with optional yq expression(s) enclosed by \"\${{ }}\"" + echo -e "\t\t\tThe \`paths\` json string should be properly escaped/quoted" + echo -e "\t\t\tExample: --paths='[{\"path\":\"foo.yaml\",\"replacements\":[{\"key\":\"bar\",\"replacement\":\"{{ .components[0]| .containerImage }}\"}]}]'" + echo -e "\t-f, --file\tPath to mapping_snapshots.json file\n" } OPTIONS=$(getopt -l "paths:,file:" -o "p:f:" -a -- "$@") @@ -46,43 +46,34 @@ if [ -z "${PATHS}" ] || [ -z "${FILE}" ]; then exit fi -newPaths=('{"paths": []}') +newPaths='{"paths": []}' +pathsLength=$(jq -cr '. |length' <<< "${PATHS}") +for(( p=0; p