Skip to content

Commit 33f9f5f

Browse files
committed
Honor excludes; don't run against entire directories (closes #121)
1 parent 2e40ade commit 33f9f5f

1 file changed

Lines changed: 2 additions & 27 deletions

File tree

terraform_fmt.sh

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
declare -a paths
5-
declare -a tfvars_files
6-
7-
index=0
8-
94
for file_with_path in "$@"; do
105
file_with_path="${file_with_path// /__REPLACED__SPACE__}"
11-
12-
paths[index]=$(dirname "$file_with_path")
13-
14-
if [[ "$file_with_path" == *".tfvars" ]]; then
15-
tfvars_files+=("$file_with_path")
16-
fi
17-
18-
let "index+=1"
19-
done
20-
21-
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
22-
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"
23-
24-
pushd "$path_uniq" > /dev/null
25-
terraform fmt
6+
pushd $(dirname "$file_with_path") > /dev/null
7+
terraform fmt $(basename "$file_with_path")
268
popd > /dev/null
279
done
28-
29-
# terraform.tfvars are excluded by `terraform fmt`
30-
for tfvars_file in "${tfvars_files[@]}"; do
31-
tfvars_file="${tfvars_file//__REPLACED__SPACE__/ }"
32-
33-
terraform fmt "$tfvars_file"
34-
done

0 commit comments

Comments
 (0)