Skip to content

Commit 611b708

Browse files
committed
fix(terraform_docs): fix config path having multiple whitespaces
1 parent 4b0ad90 commit 611b708

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

hooks/terraform_docs.sh

+10-3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function terraform_docs {
8888
local add_to_existing=false
8989
local create_if_not_exist=false
9090
local use_standard_markers=true
91+
local had_config_flag=false
9192

9293
IFS=";" read -r -a configs <<< "$hook_config"
9394

@@ -142,10 +143,11 @@ function terraform_docs {
142143
local tf_docs_formatter="md"
143144

144145
else
145-
146+
had_config_flag=true
146147
local config_file=${args#*--config}
147148
config_file=${config_file#*=}
148-
config_file=${config_file% *}
149+
config_file=${config_file% --*}
150+
args=${args/--config=$config_file/}
149151

150152
# Prioritize `.terraform-docs.yml` `output.file` over
151153
# `--hook-config=--path-to-file=` if it set
@@ -231,8 +233,13 @@ function terraform_docs {
231233
have_marker=$(grep -o "$insertion_marker_begin" "$output_file") || unset have_marker
232234
[[ ! $have_marker ]] && popd > /dev/null && continue
233235
fi
236+
if [[ $had_config_flag == true ]]; then
237+
# shellcheck disable=SC2086
238+
terraform-docs --output-mode="$output_mode" --output-file="$output_file" $tf_docs_formatter --config="$config_file" $args ./ > /dev/null
239+
else
234240
# shellcheck disable=SC2086
235-
terraform-docs --output-mode="$output_mode" --output-file="$output_file" $tf_docs_formatter $args ./ > /dev/null
241+
terraform-docs --output-mode="$output_mode" --output-file="$output_file" $tf_docs_formatter $config_arg $args ./ > /dev/null
242+
fi
236243

237244
popd > /dev/null
238245
done

0 commit comments

Comments
 (0)