mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
chore: Use lib_getopt for all hooks and some style tweaks (#137)
This commit is contained in:
parent
0c5cbb380b
commit
1d8af371d4
4 changed files with 99 additions and 1075 deletions
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
set -eo pipefail
|
||||
|
||||
main() {
|
||||
initialize_
|
||||
|
|
@ -54,14 +54,19 @@ parse_cmdline_() {
|
|||
terraform_validate_() {
|
||||
|
||||
# Setup environment variables
|
||||
local var var_name var_value
|
||||
for var in "${ENVS[@]}"; do
|
||||
export "${!var}"
|
||||
var_name="${var%%=*}"
|
||||
var_value="${var#*=}"
|
||||
# shellcheck disable=SC2086
|
||||
export $var_name="$var_value"
|
||||
done
|
||||
|
||||
declare -a paths
|
||||
index=0
|
||||
error=0
|
||||
local index=0
|
||||
local error=0
|
||||
|
||||
local file_with_path
|
||||
for file_with_path in "${FILES[@]}"; do
|
||||
file_with_path="${file_with_path// /__REPLACED__SPACE__}"
|
||||
|
||||
|
|
@ -69,12 +74,15 @@ terraform_validate_() {
|
|||
((index += 1))
|
||||
done
|
||||
|
||||
local path_uniq
|
||||
for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
|
||||
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"
|
||||
|
||||
if [[ -n "$(find "$path_uniq" -maxdepth 1 -name '*.tf' -print -quit)" ]]; then
|
||||
|
||||
local starting_path
|
||||
starting_path=$(realpath "$path_uniq")
|
||||
local terraform_path
|
||||
terraform_path="$path_uniq"
|
||||
|
||||
# Find the relevant .terraform directory (indicating a 'terraform init'),
|
||||
|
|
@ -87,6 +95,7 @@ terraform_validate_() {
|
|||
fi
|
||||
done
|
||||
|
||||
local validate_path
|
||||
validate_path="${path_uniq#"$terraform_path"}"
|
||||
|
||||
# Change to the directory that has been initialized, run validation, then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue