Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(terraform_docs): Add support for custom markers to better support other formats than Markdown #752

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,13 @@ Unlike most other hooks, this hook triggers once if there are any changed files
- --hook-config=--add-to-existing-file=true # Boolean. true or false
- --hook-config=--create-file-if-not-exist=true # Boolean. true or false
- --hook-config=--use-standard-markers=true # Boolean. Defaults to true (v1.93+), false (<v1.93). Set to true for compatibility with terraform-docs
# The following two options "--custom-marker-begin" and "--custom-marker-end" are ignored if "--use-standard-markers" is set to false
- --hook-config=--custom-marker-begin # String. Defaults to "<!-- BEGIN_TF_DOCS -->" (v1.93+), "<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->" (<v1.93).
# Set to use custom marker which helps you with using other formats like asciidoc.
# For Asciidoc this could be "--hook-config=--custom-marker-begin=// BEGIN_TF_DOCS"
- --hook-config=--custom-marker-end # String. Defaults to "<!-- END_TF_DOCS -->" (v1.93+), "<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->" (<v1.93).
# Set to use custom marker which helps you with using other formats like asciidoc.
# For Asciidoc this could be "--hook-config=--custom-marker-end=// END_TF_DOCS"
```

4. If you want to use a terraform-docs config file, you must supply the path to the file, relative to the git repo root path:
Expand Down
12 changes: 10 additions & 2 deletions hooks/terraform_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function replace_old_markers {

# Determine the appropriate sed command based on the operating system (GNU sed or BSD sed)
sed --version &> /dev/null && SED_CMD=(sed -i) || SED_CMD=(sed -i '')
"${SED_CMD[@]}" -e "s/^${old_insertion_marker_begin}$/${insertion_marker_begin}/" "$file"
"${SED_CMD[@]}" -e "s/^${old_insertion_marker_end}$/${insertion_marker_end}/" "$file"
"${SED_CMD[@]}" -e "s/^${old_insertion_marker_begin}$/${insertion_marker_begin//\//\\/}/" "$file"
"${SED_CMD[@]}" -e "s/^${old_insertion_marker_end}$/${insertion_marker_end//\//\\/}/" "$file"
}

#######################################################################
Expand Down Expand Up @@ -115,6 +115,14 @@ function terraform_docs {
common::colorify "yellow" "WARNING: --use-standard-markers is deprecated and will be removed in the future."
common::colorify "yellow" " All needed changes already done by the hook, feel free to remove --use-standard-markers setting from your pre-commit config"
;;
--custom-marker-begin)
insertion_marker_begin=$value
common::colorify "yellow" "INFO: --custom-marker-begin is used and the marker is set to \"$value\"."
;;
--custom-marker-end)
insertion_marker_end=$value
common::colorify "yellow" "INFO: --custom-marker-end is used and the marker is set to \"$value\"."
;;
esac
done

Expand Down
Loading