Skip to content

Commit ed9db97

Browse files
committed
fix(terraform-docs): follow suggestion for trimming of additional arguments in args string and format
1 parent 3adde17 commit ed9db97

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

hooks/terraform_docs.sh

+8-3
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ function terraform_docs {
145145
had_config_flag=true
146146
local config_file=${args#*--config}
147147
config_file=${config_file#*=}
148-
config_file=${config_file% --*}
149-
args=${args/--config=$config_file/}
148+
# If there are more parameters after config path, trim until --
149+
if [[ $config_file == *" --"* ]]; then
150+
config_file=${config_file%% --*}
151+
fi
152+
# Trim trailing whitespace but preserve internal spaces
153+
154+
config_file="${config_file%"${config_file##*[![:space:]]}"}" args=${args/--config=$config_file/}
150155

151156
# Prioritize `.terraform-docs.yml` `output.file` over
152157
# `--hook-config=--path-to-file=` if it set
@@ -234,7 +239,7 @@ function terraform_docs {
234239
fi
235240
local config_options=""
236241
if [[ $had_config_flag == true ]]; then
237-
config_options="--config=$config_file"
242+
config_options="--config=$config_file"
238243
fi
239244
# shellcheck disable=SC2086
240245
terraform-docs --output-mode="$output_mode" --output-file="$output_file" $tf_docs_formatter "$config_options" $args ./ > /dev/null

0 commit comments

Comments
 (0)