From 41d4951aff03f70ac72908e78a7439ff0cb8ee71 Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Sat, 21 Apr 2018 11:22:47 +0200 Subject: [PATCH] Allow to have spaces in directories (#11) --- .pre-commit-config.yaml | 3 ++- README.md | 2 +- terraform_fmt.sh | 6 ++++++ terraform_validate_no_variables.sh | 4 ++++ terraform_validate_with_variables.sh | 4 ++++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 454e4a082..70a21ad98 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,10 @@ repos: - repo: git://github.com/pre-commit/pre-commit-hooks - sha: v1.2.0 + rev: v1.2.3 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - id: check-case-conflict - id: check-merge-conflict + - id: check-executables-have-shebangs diff --git a/README.md b/README.md index b829bfaa2..8a3fa373f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ An example `.pre-commit-config.yaml`: ```yaml - repo: git://github.com/antonbabenko/pre-commit-terraform - sha: v1.5.0 + sha: v1.6.0 hooks: - id: terraform_fmt ``` diff --git a/terraform_fmt.sh b/terraform_fmt.sh index dad9a699b..d280574d1 100755 --- a/terraform_fmt.sh +++ b/terraform_fmt.sh @@ -7,6 +7,8 @@ declare -a tfvars_files index=0 for file_with_path in "$@"; do + file_with_path="${file_with_path// /__REPLACED__SPACE__}" + paths[index]=$(dirname "$file_with_path") if [[ "$file_with_path" == *".tfvars" ]]; then @@ -17,6 +19,8 @@ for file_with_path in "$@"; do done for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do + path_uniq="${path_uniq//__REPLACED__SPACE__/ }" + pushd "$path_uniq" > /dev/null terraform fmt popd > /dev/null @@ -24,5 +28,7 @@ done # terraform.tfvars are excluded by `terraform fmt` for tfvars_file in "${tfvars_files[@]}"; do + tfvars_file="${tfvars_file//__REPLACED__SPACE__/ }" + terraform fmt "$tfvars_file" done diff --git a/terraform_validate_no_variables.sh b/terraform_validate_no_variables.sh index 8aaa14063..6a43177a7 100755 --- a/terraform_validate_no_variables.sh +++ b/terraform_validate_no_variables.sh @@ -5,11 +5,15 @@ declare -a paths index=0 for file_with_path in "$@"; do + file_with_path="${file_with_path// /__REPLACED__SPACE__}" + paths[index]=$(dirname "$file_with_path") let "index+=1" done for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do + path_uniq="${path_uniq//__REPLACED__SPACE__/ }" + pushd "$path_uniq" > /dev/null terraform validate -check-variables=false diff --git a/terraform_validate_with_variables.sh b/terraform_validate_with_variables.sh index a3de4a97e..42f1b5452 100755 --- a/terraform_validate_with_variables.sh +++ b/terraform_validate_with_variables.sh @@ -5,11 +5,15 @@ declare -a paths index=0 for file_with_path in "$@"; do + file_with_path="${file_with_path// /__REPLACED__SPACE__}" + paths[index]=$(dirname "$file_with_path") let "index+=1" done for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do + path_uniq="${path_uniq//__REPLACED__SPACE__/ }" + pushd "$path_uniq" > /dev/null terraform validate -check-variables=true