From d5a98e5e5789c8180e98c27895f42f0826a96033 Mon Sep 17 00:00:00 2001 From: Maksym Vlasov Date: Mon, 9 Sep 2024 23:06:01 +0300 Subject: [PATCH] Apply suggestions from code review Co-authored-by: George L. Yermulnik --- hooks/terraform_docs.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index 4edab423b..758046908 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -264,11 +264,11 @@ function terraform_docs { #? TF 0.12+ and terraform-docs 0.12.0+ # - # If `--add-to-existing-file=false` (default behavior), check is in file exist "hook markers", - # and if not skip execution to avoid addition of terraform-docs section - - # terraform-docs in 'inject' mode adds markers by default if they not present + # If `--add-to-existing-file=false` (default behavior), check if "hook markers" exist in file, + # and, if not, skip execution to avoid addition of terraform-docs section, as + # terraform-docs in 'inject' mode adds markers by default if they are not present # - if ! $add_to_existing; then + if [[ $add_to_existing == false ]]; then HAVE_MARKER=$(grep -o "$insertion_marker_begin" "$output_file" || exit 0) [[ ! $HAVE_MARKER ]] && continue fi @@ -278,18 +278,18 @@ function terraform_docs { else #? TF 0.12+ and terraform-docs < 0.8 #? Yes, we don't cover case of TF 0.12+ and terraform-docs 0.8-0.11 - #? but I portably just drop this section in next release of the hook, - #? as there no sense to support hacks for tool versions which was released more than 3 years ago + #? but I probably just drop this section in next release of the hook, + #? as there's no sense to support hacks for tool versions which were released more than 3 years ago # - # If `--add-to-existing-file=true` set, check is in file exist "hook markers", - # and if not - append "hook markers" to the end of file. + # If `--add-to-existing-file=true` set, check if "hook markers" exist in file, + # and, if not, append "hook markers" to the end of the file. # - if $add_to_existing; then + if [[ $add_to_existing == true ]]; then HAVE_MARKER=$(grep -o "$insertion_marker_begin" "$output_file" || exit 0) - if [ ! "$HAVE_MARKER" ]; then - # Use of insertion markers, where addToExisting=true, with no markers in the existing file + if [[ ! $HAVE_MARKER ]]; then + # Use of insertion markers, when "add_to_existing=true" with no markers in the existing file echo "$insertion_marker_begin" >> "$output_file" echo "$insertion_marker_end" >> "$output_file" fi