()
| 75 | } |
| 76 | |
| 77 | func ExampleExpression_RenameVariablePrefix() { |
| 78 | src := []byte( |
| 79 | "foo = a.x + a.y * b.c\n" + |
| 80 | "bar = max(a.z, b.c)\n", |
| 81 | ) |
| 82 | f, diags := hclwrite.ParseConfig(src, "", hcl.Pos{Line: 1, Column: 1}) |
| 83 | if diags.HasErrors() { |
| 84 | fmt.Printf("errors: %s", diags) |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | // Rename references of variable "a" to "z" |
| 89 | for _, attr := range f.Body().Attributes() { |
| 90 | attr.Expr().RenameVariablePrefix( |
| 91 | []string{"a"}, |
| 92 | []string{"z"}, |
| 93 | ) |
| 94 | } |
| 95 | |
| 96 | fmt.Printf("%s", f.Bytes()) |
| 97 | // Output: |
| 98 | // foo = z.x + z.y * b.c |
| 99 | // bar = max(z.z, b.c) |
| 100 | } |
nothing calls this directly
no test coverage detected