From e40ffc76df4d24fa617c46094c934847334b12c0 Mon Sep 17 00:00:00 2001 From: MaxymVlasov Date: Tue, 10 Sep 2024 21:08:57 +0300 Subject: [PATCH] Drop useless intemediate steps --- hooks/terraform_docs.sh | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index 5bfc68a75..822dcec4d 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -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[@]}" } ####################################################################### @@ -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 @@ -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 @@ -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