Skip to content

Commit

Permalink
Drop useless intemediate steps
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxymVlasov committed Sep 10, 2024
1 parent 7b5824e commit e40ffc7
Showing 1 changed file with 7 additions and 27 deletions.
34 changes: 7 additions & 27 deletions hooks/terraform_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function main {
ARGS[i]=${ARGS[i]/--config=/--config=$(pwd)\/}
done
# shellcheck disable=SC2153 # False positive
terraform_docs_ "${HOOK_CONFIG[*]}" "${ARGS[*]}" "${FILES[@]}"
terraform_docs "${HOOK_CONFIG[*]}" "${ARGS[*]}" "${FILES[@]}"
}

#######################################################################
Expand All @@ -46,31 +46,6 @@ function replace_old_markers {
"${SED_CMD[@]}" -e "s/^${old_insertion_marker_end}$/${insertion_marker_end}/" "$file"
}

#######################################################################
# Function which prepares hacks for old versions of `terraform` and
# `terraform-docs` that them call `terraform_docs`
# Arguments:
# hook_config (string with array) arguments that configure hook behavior
# args (string with array) arguments that configure wrapped tool behavior
# files (array) filenames to check
#######################################################################
function terraform_docs_ {
local -r hook_config="$1"
local -r args="$2"
shift 2
local -a -r files=("$@")

# Get hook settings
IFS=";" read -r -a configs <<< "$hook_config"

if [[ ! $(command -v terraform-docs) ]]; then
echo "ERROR: terraform-docs is required by terraform_docs pre-commit hook but is not installed or in the system's PATH."
exit 1
fi

terraform_docs "${configs[*]}" "$args" "${files[@]}"
}

#######################################################################
# Wrapper around `terraform-docs` tool that check and change/create
# (depends on provided hook_config) terraform documentation in
Expand All @@ -86,6 +61,11 @@ function terraform_docs {
shift 2
local -a -r files=("$@")

if [[ ! $(command -v terraform-docs) ]]; then
echo "ERROR: terraform-docs is required by terraform_docs pre-commit hook but is not installed or in the system's PATH."
exit 1
fi

local -a paths

local index=0
Expand All @@ -108,7 +88,7 @@ function terraform_docs {
local create_if_not_exist=false
local use_standard_markers=true

read -r -a configs <<< "$hook_config"
IFS=";" read -r -a configs <<< "$hook_config"

for c in "${configs[@]}"; do

Expand Down

0 comments on commit e40ffc7

Please sign in to comment.