@@ -121,6 +121,7 @@ function terraform_docs {
121
121
# Get hook settings
122
122
#
123
123
local text_file=" README.md"
124
+ local use_path_to_file=false
124
125
local add_to_existing=false
125
126
local create_if_not_exist=false
126
127
local use_standard_markers=false
@@ -136,6 +137,7 @@ function terraform_docs {
136
137
case $key in
137
138
--path-to-file)
138
139
text_file=$value
140
+ use_path_to_file=true
139
141
;;
140
142
--add-to-existing-file)
141
143
add_to_existing=$value
@@ -159,13 +161,29 @@ function terraform_docs {
159
161
if [[ " $args " != * " --config" * ]]; then
160
162
local tf_docs_formatter=" md"
161
163
162
- # Suppress terraform_docs color
163
164
else
164
165
165
166
local config_file=${args#* --config}
166
167
config_file=${config_file#* =}
167
168
config_file=${config_file% * }
168
169
170
+ # Prioritize `.terraform-docs.yml` `output.file` over
171
+ # `--hook-config=--path-to-file=` if it set
172
+ local output_file
173
+ # Get latest non-commented `output.file` from `.terraform-docs.yml`
174
+ output_file=$( grep -A1000 -e ' ^output:$' " $config_file " | grep -E ' ^[[:space:]]+file:' | tail -n 1) || true
175
+
176
+ if [[ $output_file ]]; then
177
+ # Extract filename from `output.file` line
178
+ text_file=$( echo " $output_file " | awk -F' :' ' {print $2}' | tr -d ' [:space:]"' | tr -d " '" )
179
+
180
+ if [[ $use_path_to_file ]]; then
181
+ common::colorify " yellow" " NOTE: You set both '--hook-config=--path-to-file=' and 'output.file' in '$config_file '"
182
+ common::colorify " yellow" " 'output.file' from '$config_file ' will be used."
183
+ fi
184
+ fi
185
+
186
+ # Suppress terraform_docs color
169
187
local config_file_no_color
170
188
config_file_no_color=" $config_file $( date +%s) .yml"
171
189
@@ -228,7 +246,7 @@ function terraform_docs {
228
246
229
247
if [[ " $terraform_docs_awk_file " == " 0" ]]; then
230
248
# shellcheck disable=SC2086
231
- terraform-docs $tf_docs_formatter $args ./ > " $tmp_file "
249
+ terraform-docs --output-file= " " $tf_docs_formatter $args ./ > " $tmp_file "
232
250
else
233
251
# Can't append extension for mktemp, so renaming instead
234
252
local tmp_file_docs
@@ -239,7 +257,7 @@ function terraform_docs {
239
257
240
258
awk -f " $terraform_docs_awk_file " ./* .tf > " $tmp_file_docs_tf "
241
259
# shellcheck disable=SC2086
242
- terraform-docs $tf_docs_formatter $args " $tmp_file_docs_tf " > " $tmp_file "
260
+ terraform-docs --output-file= " " $tf_docs_formatter $args " $tmp_file_docs_tf " > " $tmp_file "
243
261
rm -f " $tmp_file_docs_tf "
244
262
fi
245
263
0 commit comments