Skip to content

Commit

Permalink
Fix terraform-docs with default value with reserved words
Browse files Browse the repository at this point in the history
If default value has reserved words (description, type), awk failed.
From this PR antonbabenko/pre-commit-terraform#66, I tried to fix default value awk transformation
  • Loading branch information
eservent authored Oct 8, 2019
1 parent ccf99fb commit 21a6432
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions bin/terraform-docs.awk
Original file line number Diff line number Diff line change
Expand Up @@ -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 "\""
}
}
}
}
}
}
Expand Down

0 comments on commit 21a6432

Please sign in to comment.