Skip to content

Commit b0573e7

Browse files
committed
fix(terraform_docs): Fix bug introduced in v1.97.2
* Fix bug introduced via #796 by passing config file only when it is defined * While here make array declarations in `common::parse_cmdline` in `hooks/_common.sh` compliant with Bash v3 * While here suppress error outputs from `grep` for non-existing config file in `hooks/terraform_docs.sh` where error output makes no sense
1 parent 03d6270 commit b0573e7

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

hooks/_common.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ function common::initialize {
5252
function common::parse_cmdline {
5353
# common global arrays.
5454
# Populated via `common::parse_cmdline` and can be used inside hooks' functions
55-
ARGS=() HOOK_CONFIG=() FILES=()
55+
ARGS=()
56+
HOOK_CONFIG=()
57+
FILES=()
5658
# Used inside `common::terraform_init` function
5759
TF_INIT_ARGS=()
5860
# Used inside `common::export_provided_env_vars` function

hooks/terraform_docs.sh

+15-6
Original file line numberDiff line numberDiff line change
@@ -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,19 @@ 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+
local tfdocs_cmd=(
245+
terraform-docs
246+
--output-mode="$output_mode"
247+
--output-file="$output_file"
248+
$tf_docs_formatter
249+
$args
250+
)
251+
if [[ $have_config_flag == true ]]; then
252+
${tfdocs_cmd[@]} "--config=$config_file" ./ > /dev/null
253+
else
254+
${tfdocs_cmd[@]} ./ > /dev/null
255+
fi
247256

248257
popd > /dev/null
249258
done

0 commit comments

Comments
 (0)