Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#152 Ensure terraform-docs 0.12 multi-line default statement is parsed correctly #155

Merged
merged 2 commits into from
Jun 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 53 additions & 19 deletions bin/terraform-docs.awk
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,76 @@
# https://github.com/segmentio/terraform-docs/issues/62

{
if ( /\{/ ) {
braceCnt++
if ( /\{/ ) {
braceCnt++
}

if ( /\}/ ) {
braceCnt--
if ( /\}/ ) {
braceCnt--
}

# [START] variable or output block started
if ($0 ~ /(variable|output) "(.*?)"/) {
# [CLOSE] "default" block
if (blockDefCnt > 0) {
blockDefCnt = 0
}
blockCnt++
print $0
}

if ($1 == "description") {
print $0
# [START] multiline default statement started
if (blockCnt > 0) {
if ($1 == "default") {
print $0
if ($NF ~ /[\[\(\{]/) {
blockDefCnt++
blockDefStart=1
}
}
}

if ($1 == "default") {
if (braceCnt > 1) {
print " default = {}"
} else {
# [PRINT] single line "description"
if (blockDefCnt == 0) {
if ($1 == "description") {
# [CLOSE] "default" block
if (blockDefCnt > 0) {
blockDefCnt = 0
}
print $0
}
}

if ($1 == "type" ) {
type=$3
if (type ~ "object") {
print " type = \"object\""
} else {
print " type = \"" $3 "\""
# [PRINT] single line "type"
if (blockCnt > 0) {
if ($1 == "type" ) {
# [CLOSE] "default" block
if (blockDefCnt > 0) {
blockDefCnt = 0
}
type=$3
if (type ~ "object") {
print " type = \"object\""
} else {
print " type = \"" $3 "\""
}
}
}

if (braceCnt == 0 && blockCnt > 0) {
blockCnt--
print $0
# [CLOSE] variable/output block
if (blockCnt > 0) {
if (braceCnt == 0 && blockCnt > 0) {
blockCnt--
print $0
}
}

# [PRINT] Multiline "default" statement
if (blockCnt > 0 && blockDefCnt > 0) {
if (blockDefStart == 1) {
blockDefStart = 0
} else {
print $0
}
}
}