diff --git a/scripts/01_update_output.sh b/scripts/01_update_output.sh index 07732f9..4a6ad0c 100755 --- a/scripts/01_update_output.sh +++ b/scripts/01_update_output.sh @@ -4,12 +4,7 @@ set -xueo pipefail source "$(dirname $0)/utils.sh" goto_root -TO_PARSE="." -if [ ! -z ${1+x} ]; then - TO_PARSE="$1" -fi - -for path in $(find $TO_PARSE -path ./incubator -prune -o -name 'monitors-*.tf' -print); do +for path in $(find "$(get_scope $1)" -path ./incubator -prune -o -name 'monitors-*.tf' -print); do cd $(dirname $path) > outputs.tf for monitor in $(grep 'resource "datadog_monitor"' $(basename $path) | awk '{print $3}' | tr -d '"' ); do @@ -24,4 +19,4 @@ EOF done cd - >> /dev/null done -terraform fmt $TO_PARSE +terraform fmt "$(get_scope $1)" diff --git a/scripts/02_update_readme.sh b/scripts/02_update_readme.sh index e59a887..1c88a3b 100755 --- a/scripts/02_update_readme.sh +++ b/scripts/02_update_readme.sh @@ -4,11 +4,6 @@ set -xueo pipefail source "$(dirname $0)/utils.sh" goto_root -TO_PARSE="." -if [ ! -z ${1+x} ]; then - TO_PARSE="$1" -fi - sed -i '/### Monitors summary ###/q' README.md echo >> README.md for path in $(find -mindepth 1 \( -path './incubator' -o -path './scripts' -o -path './testing' -o -path '*/\.*' \) -prune -o -type d -print | sort); do @@ -25,7 +20,7 @@ done PATTERN_DOC="Related documentation" -for path in $(find $TO_PARSE -path ./incubator -prune -o -name 'monitors-*.tf' -print); do +for path in $(find "$(get_scope $1)" -path ./incubator -prune -o -name 'monitors-*.tf' -print); do cd $(dirname $path) EXIST=0 if [ -f README.md ]; then diff --git a/scripts/auto_update.sh b/scripts/auto_update.sh index a2ef8d5..b584166 100755 --- a/scripts/auto_update.sh +++ b/scripts/auto_update.sh @@ -1,12 +1,10 @@ #!/bin/bash set -xueo pipefail -TO_PARSE="." -if [ ! -z ${1+x} ]; then - TO_PARSE="$1" -fi +source "$(dirname $0)/utils.sh" cd $(dirname $0) + for script in [0-9][0-9]_*.sh; do - ./${script} $TO_PARSE + ./${script} "$(get_scope $1)" done diff --git a/scripts/utils.sh b/scripts/utils.sh index b9dbdf8..b4b23ca 100755 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -9,6 +9,14 @@ function goto_root { fi } +function get_scope { + TO_PARSE="." + if [ ! -z ${1+x} ]; then + TO_PARSE="$1" + fi + echo $TO_PARSE +} + function list_dirs { echo ${1} | awk -F '/' '{$1=""; print $0}' | cut -c 2- }