From bc1c2f6e7b5381447641dfd808088abf77fab64d Mon Sep 17 00:00:00 2001 From: Lawrence Goldstien Date: Wed, 18 May 2022 11:43:41 +0100 Subject: [PATCH 1/5] feat: When a config file is given, do not specify formatter on cli --- hooks/terraform_docs.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index 821866afc..b502e7435 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -135,6 +135,15 @@ function terraform_docs { esac done + # + # Decide formatter to use + # + local tf_docs_formatter="md" + if [[ "$args" == *"--config"* ]]; then + # Allow config file to specify formatter + tf_docs_formatter="" + fi + local dir_path for dir_path in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do dir_path="${dir_path//__REPLACED__SPACE__/ }" @@ -181,7 +190,7 @@ function terraform_docs { if [[ "$terraform_docs_awk_file" == "0" ]]; then # shellcheck disable=SC2086 - terraform-docs md $args ./ > "$tmp_file" + terraform-docs $tf_docs_formatter $args ./ > "$tmp_file" else # Can't append extension for mktemp, so renaming instead local tmp_file_docs @@ -192,7 +201,7 @@ function terraform_docs { awk -f "$terraform_docs_awk_file" ./*.tf > "$tmp_file_docs_tf" # shellcheck disable=SC2086 - terraform-docs md $args "$tmp_file_docs_tf" > "$tmp_file" + terraform-docs $tf_docs_formatter $args "$tmp_file_docs_tf" > "$tmp_file" rm -f "$tmp_file_docs_tf" fi From 58f26a7bbfaf85f43f2c71a1923bd6d5af06a0be Mon Sep 17 00:00:00 2001 From: Lawrence <34475808+acodeninja@users.noreply.github.com> Date: Wed, 18 May 2022 13:32:17 +0100 Subject: [PATCH 2/5] unset tf_docs_formatter variable instead of setting to empty Co-authored-by: George L. Yermulnik --- hooks/terraform_docs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index b502e7435..5c61559be 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -141,7 +141,7 @@ function terraform_docs { local tf_docs_formatter="md" if [[ "$args" == *"--config"* ]]; then # Allow config file to specify formatter - tf_docs_formatter="" + unset tf_docs_formatter fi local dir_path From 00b26392658a193f2d5038fbfdb73ceb02585c37 Mon Sep 17 00:00:00 2001 From: Lawrence Goldstien Date: Wed, 18 May 2022 14:15:46 +0100 Subject: [PATCH 3/5] Only set tf_docs_formatter if --config arg not included --- hooks/terraform_docs.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index 5c61559be..d48272338 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -136,13 +136,9 @@ function terraform_docs { done # - # Decide formatter to use + # Override formatter if no config file set # - local tf_docs_formatter="md" - if [[ "$args" == *"--config"* ]]; then - # Allow config file to specify formatter - unset tf_docs_formatter - fi + [[ "$args" != *"--config"* ]] && local tf_docs_formatter="md" local dir_path for dir_path in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do From ace146045fc28dbf8e7c8a007926fa8024d77616 Mon Sep 17 00:00:00 2001 From: Lawrence Goldstien Date: Wed, 18 May 2022 14:43:24 +0100 Subject: [PATCH 4/5] Move to using regex for config test and align with reqs for = sign --- hooks/terraform_docs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index d48272338..86e940e0e 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -138,7 +138,7 @@ function terraform_docs { # # Override formatter if no config file set # - [[ "$args" != *"--config"* ]] && local tf_docs_formatter="md" + [[ ! $args =~ (^|[[:space:]])--config=[^[:space:]]+ ]] && local tf_docs_formatter="md" local dir_path for dir_path in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do From 855f9c52ed0e717dd953a3cbe445bfee1cd17662 Mon Sep 17 00:00:00 2001 From: Lawrence Goldstien Date: Wed, 18 May 2022 15:35:18 +0100 Subject: [PATCH 5/5] Moved back to string contains syntax for bash v3 --- hooks/terraform_docs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index 86e940e0e..63a65fd4b 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -138,7 +138,7 @@ function terraform_docs { # # Override formatter if no config file set # - [[ ! $args =~ (^|[[:space:]])--config=[^[:space:]]+ ]] && local tf_docs_formatter="md" + [[ "$args" != *"--config="* ]] && local tf_docs_formatter="md" local dir_path for dir_path in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do