diff --git a/README.md b/README.md index 6bfb50225..bbce9d522 100644 --- a/README.md +++ b/README.md @@ -608,6 +608,16 @@ 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 ( # String. + # 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. + # 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" + - --hook-config=--custom-doc-header="# " # String. Defaults to "# " + # Set to use custom marker which helps you with using other formats like asciidoc. + # For Asciidoc this could be "--hook-config=--custom-marker-end=\= " ``` 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: diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index 3d0cc884a..accbb02a1 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -9,6 +9,7 @@ readonly SCRIPT_DIR insertion_marker_begin="" insertion_marker_end="" +doc_header="# " # Old markers used by the hook before the introduction of the terraform-docs markers readonly old_insertion_marker_begin="" @@ -42,8 +43,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" } ####################################################################### @@ -115,6 +116,18 @@ 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 "green" "INFO: --custom-marker-begin is used and the marker is set to \"$value\"." + ;; + --custom-marker-end) + insertion_marker_end=$value + common::colorify "green" "INFO: --custom-marker-end is used and the marker is set to \"$value\"." + ;; + --custom-doc-header) + doc_header=$value + common::colorify "green" "INFO: --custom-doc-header is used and the doc header is set to \"$value\"." + ;; esac done @@ -198,7 +211,7 @@ function terraform_docs { # Use of insertion markers, where there is no existing README file { - echo -e "# ${PWD##*/}\n" + echo -e "${doc_header}${PWD##*/}\n" echo "$insertion_marker_begin" echo "$insertion_marker_end" } >> "$output_file"