From f2cab31bc41e913ea63b92b6fc0b3b6e2a2c039a Mon Sep 17 00:00:00 2001 From: Sergei Ivanov Date: Mon, 7 Sep 2020 14:50:57 +0100 Subject: [PATCH] fix: Correctly handle arrays in terraform_docs.sh (#141) --- .pre-commit-config.yaml | 4 ++-- terraform_docs.sh | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9b4a494..90e69ba 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: git://github.com/pre-commit/pre-commit-hooks - rev: v2.5.0 + rev: v3.2.0 hooks: - id: check-yaml - id: end-of-file-fixer @@ -9,7 +9,7 @@ repos: - id: check-merge-conflict - id: check-executables-have-shebangs - repo: git://github.com/jumanjihouse/pre-commit-hooks - rev: 2.0.0 + rev: 2.1.4 hooks: - id: shfmt args: ['-l', '-i', '2', '-ci', '-sr', '-w'] diff --git a/terraform_docs.sh b/terraform_docs.sh index 52242a5..ae898bc 100755 --- a/terraform_docs.sh +++ b/terraform_docs.sh @@ -4,7 +4,7 @@ set -eo pipefail main() { initialize_ parse_cmdline_ "$@" - terraform_docs_ "$ARGS" "$FILES" + terraform_docs_ "${ARGS[*]}" "${FILES[@]}" } initialize_() { @@ -48,7 +48,8 @@ parse_cmdline_() { terraform_docs_() { local -r args="$1" - local -r files="$2" + shift + local -a -r files=("$@") local hack_terraform_docs hack_terraform_docs=$(terraform version | head -1 | grep -c 0.12) || true @@ -63,7 +64,7 @@ terraform_docs_() { if [[ -z "$is_old_terraform_docs" ]]; then # Using terraform-docs 0.8+ (preferred) - terraform_docs "0" "$args" "$files" + terraform_docs "0" "$args" "${files[@]}" elif [[ "$hack_terraform_docs" == "1" ]]; then # Using awk script because terraform-docs is older than 0.8 and terraform 0.12 is used @@ -75,12 +76,12 @@ terraform_docs_() { local tmp_file_awk tmp_file_awk=$(mktemp "${TMPDIR:-/tmp}/terraform-docs-XXXXXXXXXX") terraform_docs_awk "$tmp_file_awk" - terraform_docs "$tmp_file_awk" "$args" "$files" + terraform_docs "$tmp_file_awk" "$args" "${files[@]}" rm -f "$tmp_file_awk" else # Using terraform 0.11 and no awk script is needed for that - terraform_docs "0" "$args" "$files" + terraform_docs "0" "$args" "${files[@]}" fi } @@ -88,14 +89,15 @@ terraform_docs_() { terraform_docs() { local -r terraform_docs_awk_file="$1" local -r args="$2" - local -r files="$3" + shift 2 + local -a -r files=("$@") declare -a paths declare -a tfvars_files local index=0 local file_with_path - for file_with_path in $files; do + for file_with_path in "${files[@]}"; do file_with_path="${file_with_path// /__REPLACED__SPACE__}" paths[index]=$(dirname "$file_with_path")