mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
fix: Correctly handle arrays in terraform_docs.sh (#141)
This commit is contained in:
parent
f2e3a5f796
commit
f2cab31bc4
2 changed files with 11 additions and 9 deletions
|
|
@ -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']
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue