Skip to content

Commit f2cab31

Browse files
fix: Correctly handle arrays in terraform_docs.sh (antonbabenko#141)
1 parent f2e3a5f commit f2cab31

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: git://github.com/pre-commit/pre-commit-hooks
3-
rev: v2.5.0
3+
rev: v3.2.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
@@ -9,7 +9,7 @@ repos:
99
- id: check-merge-conflict
1010
- id: check-executables-have-shebangs
1111
- repo: git://github.com/jumanjihouse/pre-commit-hooks
12-
rev: 2.0.0
12+
rev: 2.1.4
1313
hooks:
1414
- id: shfmt
1515
args: ['-l', '-i', '2', '-ci', '-sr', '-w']

terraform_docs.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -eo pipefail
44
main() {
55
initialize_
66
parse_cmdline_ "$@"
7-
terraform_docs_ "$ARGS" "$FILES"
7+
terraform_docs_ "${ARGS[*]}" "${FILES[@]}"
88
}
99

1010
initialize_() {
@@ -48,7 +48,8 @@ parse_cmdline_() {
4848

4949
terraform_docs_() {
5050
local -r args="$1"
51-
local -r files="$2"
51+
shift
52+
local -a -r files=("$@")
5253

5354
local hack_terraform_docs
5455
hack_terraform_docs=$(terraform version | head -1 | grep -c 0.12) || true
@@ -63,7 +64,7 @@ terraform_docs_() {
6364

6465
if [[ -z "$is_old_terraform_docs" ]]; then # Using terraform-docs 0.8+ (preferred)
6566

66-
terraform_docs "0" "$args" "$files"
67+
terraform_docs "0" "$args" "${files[@]}"
6768

6869
elif [[ "$hack_terraform_docs" == "1" ]]; then # Using awk script because terraform-docs is older than 0.8 and terraform 0.12 is used
6970

@@ -75,27 +76,28 @@ terraform_docs_() {
7576
local tmp_file_awk
7677
tmp_file_awk=$(mktemp "${TMPDIR:-/tmp}/terraform-docs-XXXXXXXXXX")
7778
terraform_docs_awk "$tmp_file_awk"
78-
terraform_docs "$tmp_file_awk" "$args" "$files"
79+
terraform_docs "$tmp_file_awk" "$args" "${files[@]}"
7980
rm -f "$tmp_file_awk"
8081

8182
else # Using terraform 0.11 and no awk script is needed for that
8283

83-
terraform_docs "0" "$args" "$files"
84+
terraform_docs "0" "$args" "${files[@]}"
8485

8586
fi
8687
}
8788

8889
terraform_docs() {
8990
local -r terraform_docs_awk_file="$1"
9091
local -r args="$2"
91-
local -r files="$3"
92+
shift 2
93+
local -a -r files=("$@")
9294

9395
declare -a paths
9496
declare -a tfvars_files
9597

9698
local index=0
9799
local file_with_path
98-
for file_with_path in $files; do
100+
for file_with_path in "${files[@]}"; do
99101
file_with_path="${file_with_path// /__REPLACED__SPACE__}"
100102

101103
paths[index]=$(dirname "$file_with_path")

0 commit comments

Comments
 (0)