Skip to content

Commit

Permalink
Some count parameters take a bare %s string parameter instead of …
Browse files Browse the repository at this point in the history
…a `%d`
  • Loading branch information
gdavison committed Aug 9, 2022
1 parent abcc3d0 commit 25b19e0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/fmtverbs/fmtverbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func Escape(b string) string {
b = regexp.MustCompile(`(\bprovider\s+=\s+)+%\[(\d+)\]s`).ReplaceAllString(b, `${1}tfmtprovider.PROVIDER_${2}`)

// count meta-argument
b = regexp.MustCompile(`(\bcount\s+=\s+)%(d)`).ReplaceAllString(b, `${1}1 # tfmtcount_${2}`)
b = regexp.MustCompile(`(\bcount\s+=\s+)+%(\[(\d+)\]d)`).ReplaceAllString(b, `${1}1 # tfmtcount_${2}`)
b = regexp.MustCompile(`(\bcount\s+=\s+)%([ds])`).ReplaceAllString(b, `${1}1 # tfmtcount_${2}`)
b = regexp.MustCompile(`(\bcount\s+=\s+)+%(\[(\d+)\][ds])`).ReplaceAllString(b, `${1}1 # tfmtcount_${2}`)

// %[n]s
b = regexp.MustCompile(`(?m:^%(\.[0-9])?\[[\d]+\][sdfgtq]$)`).ReplaceAllString(b, `#@@_@@ TFMT:$0:TMFT @@_@@#`)
Expand Down Expand Up @@ -129,8 +129,8 @@ func Unscape(fb string) string {
fb = regexp.MustCompile(`"TFMTRESNAME_q"`).ReplaceAllLiteralString(fb, `%q`)

// count meta-argument
fb = regexp.MustCompile(`1\s+# tfmtcount_(\[\d+\]d)`).ReplaceAllString(fb, `%${1}`)
fb = regexp.MustCompile(`1\s+# tfmtcount_d`).ReplaceAllString(fb, `%d`)
fb = regexp.MustCompile(`1\s+# tfmtcount_(\[\d+\][ds])`).ReplaceAllString(fb, `%${1}`)
fb = regexp.MustCompile(`1\s+# tfmtcount_([ds])`).ReplaceAllString(fb, `%${1}`)

// provider meta-argument
fb = regexp.MustCompile(`tfmtprovider.PROVIDER_(\d+)`).ReplaceAllString(fb, `%[${1}]s`)
Expand Down
24 changes: 20 additions & 4 deletions lib/fmtverbs/fmtverbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,19 @@ resource "resource" "test2" {
count = %[2]d
}
resource "other_resource" "test3" {
resource "resource" "test3" {
count = %s
}
resource "resource" "test4" {
count = %[3]s
}
resource "other_resource" "test5" {
replica_count = %d
}
resource "other_resource" "test4" {
resource "other_resource" "test6" {
replica_count = %[2]d
}
`,
Expand All @@ -600,11 +608,19 @@ resource "resource" "test2" {
count = 1 # tfmtcount_[2]d
}
resource "other_resource" "test3" {
resource "resource" "test3" {
count = 1 # tfmtcount_s
}
resource "resource" "test4" {
count = 1 # tfmtcount_[3]s
}
resource "other_resource" "test5" {
replica_count = "@@_@@ TFMT:%d:TFMT @@_@@"
}
resource "other_resource" "test4" {
resource "other_resource" "test6" {
replica_count = "@@_@@ TFMT:%[2]d:TFMT @@_@@"
}
`,
Expand Down

0 comments on commit 25b19e0

Please sign in to comment.