From eea3477acb7c8481cabf2cd10bd1ed4098cb8682 Mon Sep 17 00:00:00 2001 From: Quentin Manfroi Date: Tue, 17 Jul 2018 14:58:41 +0200 Subject: [PATCH] MON-259 use regex to avoid name matching --- scripts/02_update_readme.sh | 5 +++-- scripts/utils.sh | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/02_update_readme.sh b/scripts/02_update_readme.sh index a58c109..4d7da1b 100755 --- a/scripts/02_update_readme.sh +++ b/scripts/02_update_readme.sh @@ -53,8 +53,9 @@ Creates DataDog monitors with the following checks : EOF SAVEIFS=$IFS IFS=$(echo -en "\n\b") - for match in $(grep name $(basename ${path})); do - echo "- $(get_name "${match}")" >> README.md + for match in $(grep -E ^[[:space:]]+name[[:space:]]+= $(basename ${path})); do + name=$(get_name "${match}") + echo "- $name" >> README.md done IFS=$SAVEIFS terraform-docs md ./ >> README.md diff --git a/scripts/utils.sh b/scripts/utils.sh index 7ef9924..503ea86 100755 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -18,11 +18,12 @@ function get_name { if [[ "${1}" =~ ${regex} ]]; then name="${BASH_REMATCH[1]}" else + echo "Error: impossible to parse monitor name" return 42 fi if [[ "${name}" =~ ^(.*)[[:space:]]\{\{#is_alert\}\}.*$ ]]; then - echo "${BASH_REMATCH[1]}" - else - echo $name + name="${BASH_REMATCH[1]}" fi + echo $name + return 0 }