@@ -160,7 +160,7 @@ function terraform_docs {
160160 # `--hook-config=--path-to-file=` if it set
161161 local config_output_file
162162 # Get latest non-commented `output.file` from `.terraform-docs.yml`
163- config_output_file=$( grep -A1000 -e ' ^output:$' " $config_file " | grep -E ' ^[[:space:]]+file:' | tail -n 1) || true
163+ config_output_file=$( grep -A1000 -e ' ^output:$' " $config_file " 2> /dev/null | grep -E ' ^[[:space:]]+file:' | tail -n 1) || true
164164
165165 if [[ $config_output_file ]]; then
166166 # Extract filename from `output.file` line
@@ -176,7 +176,7 @@ function terraform_docs {
176176
177177 # Use `.terraform-docs.yml` `output.mode` if it set
178178 local config_output_mode
179- config_output_mode=$( grep -A1000 -e ' ^output:$' " $config_file " | grep -E ' ^[[:space:]]+mode:' | tail -n 1) || true
179+ config_output_mode=$( grep -A1000 -e ' ^output:$' " $config_file " 2> /dev/null | grep -E ' ^[[:space:]]+mode:' | tail -n 1) || true
180180 if [[ $config_output_mode ]]; then
181181 # Extract mode from `output.mode` line
182182 output_mode=$( echo " $config_output_mode " | awk -F' :' ' {print $2}' | tr -d ' [:space:]"' | tr -d " '" )
@@ -240,10 +240,21 @@ function terraform_docs {
240240 have_marker=$( grep -o " $insertion_marker_begin " " $output_file " ) || unset have_marker
241241 [[ ! $have_marker ]] && popd > /dev/null && continue
242242 fi
243- local config_options
244- [[ $have_config_flag == true ]] && config_options=" --config=$config_file "
245- # shellcheck disable=SC2086
246- terraform-docs --output-mode=" $output_mode " --output-file=" $output_file " $tf_docs_formatter " $config_options " $args ./ > /dev/null
243+
244+ # shellcheck disable=SC2206
245+ # Need to pass $tf_docs_formatter and $args as separate arguments, not as single string
246+ local tfdocs_cmd=(
247+ terraform-docs
248+ --output-mode=" $output_mode "
249+ --output-file=" $output_file "
250+ $tf_docs_formatter
251+ $args
252+ )
253+ if [[ $have_config_flag == true ]]; then
254+ " ${tfdocs_cmd[@]} " " --config=$config_file " ./ > /dev/null
255+ else
256+ " ${tfdocs_cmd[@]} " ./ > /dev/null
257+ fi
247258
248259 popd > /dev/null
249260 done
0 commit comments