From 21a6432b1547554fc0e43f695e50931939dabfc0 Mon Sep 17 00:00:00 2001 From: Emmanuel Servent Date: Tue, 8 Oct 2019 14:13:11 +0200 Subject: [PATCH 1/2] Fix terraform-docs with default value with reserved words If default value has reserved words (description, type), awk failed. From this PR https://github.com/antonbabenko/pre-commit-terraform/pull/66, I tried to fix default value awk transformation --- bin/terraform-docs.awk | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/bin/terraform-docs.awk b/bin/terraform-docs.awk index bd6b2b7f..63403e2b 100644 --- a/bin/terraform-docs.awk +++ b/bin/terraform-docs.awk @@ -45,28 +45,34 @@ if (blockDefCnt > 0) { blockDefCnt = 0 } - print $0 + if ($blockDefCnt !~ /(string|number|bool)$/) { + print $0 + } } } } # [PRINT] single line "type" if (blockCnt > 0) { - if ($0 ~ /^[[:space:]][[:space:]]*type[[:space:]][[:space:]]*=/ ) { - # [CLOSE] "default" block - if (blockDefCnt > 0) { - blockDefCnt = 0 - } - type=$3 - if (type ~ "object") { - print " type = \"object\"" - } else { - # legacy quoted types: "string", "list", and "map" - if ($3 ~ /^[[:space:]]*"(.*?)"[[:space:]]*$/) { - print " type = " $3 + if (blockDefCnt == 0) { + if ($0 ~ /^[[:space:]][[:space:]]*type[[:space:]][[:space:]]*=/ ) { + # [CLOSE] "default" block + if (blockDefCnt > 0) { + blockDefCnt = 0 + } + type=$3 + if ($blockDefCnt !~ /(string|number|bool)$/) { + if (type ~ "object") { + print " type = \"object\"" } else { - print " type = \"" $3 "\"" + # legacy quoted types: "string", "list", and "map" + if ($3 ~ /^[[:space:]]*"(.*?)"[[:space:]]*$/) { + print " type = " $3 + } else { + print " type = \"" $3 "\"" + } } + } } } } From 2f630e710d385f11b07b18e7814fdc8a01e1ca44 Mon Sep 17 00:00:00 2001 From: Emmanuel Servent Date: Fri, 18 Oct 2019 14:07:26 +0200 Subject: [PATCH 2/2] Fix type conversion --- bin/terraform-docs.awk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/terraform-docs.awk b/bin/terraform-docs.awk index 63403e2b..b19d41ed 100644 --- a/bin/terraform-docs.awk +++ b/bin/terraform-docs.awk @@ -61,7 +61,7 @@ blockDefCnt = 0 } type=$3 - if ($blockDefCnt !~ /(string|number|bool)$/) { + if ($blockDefCnt !~ /string$/) { if (type ~ "object") { print " type = \"object\"" } else {