fix: Correctly handle arrays in terraform_docs.sh (#141)

This commit is contained in:
Sergei Ivanov 2020-09-07 14:50:57 +01:00 committed by GitHub
commit f2cab31bc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View file

@ -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']

View file

@ -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")