Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: George L. Yermulnik <[email protected]>
  • Loading branch information
MaxymVlasov and yermulnik authored Sep 9, 2024
1 parent c0b1f38 commit d5a98e5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions hooks/terraform_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d5a98e5

Please sign in to comment.