MCPcopy
hub / github.com/hashicorp/hcl / RenameAttribute

Method RenameAttribute

hclwrite/ast_body.go:111–119  ·  view source on GitHub ↗

RenameAttribute changes the attribute named fromName to toName. Takes no action if fromName is missing or there is already a conflicting attribute called toName. Returns true if the rename succeeded.

(fromName, toName string)

Source from the content-addressed store, hash-verified

109//
110// Returns true if the rename succeeded.
111func (b *Body) RenameAttribute(fromName, toName string) bool {
112 attr := b.GetAttribute(fromName)
113 conflictingAttr := b.GetAttribute(toName)
114 if attr == nil || conflictingAttr != nil {
115 return false
116 }
117 attr.setName(toName)
118 return true
119}
120
121// FirstMatchingBlock returns a first matching block from the body that has the
122// given name and labels or returns nil if there is currently no matching

Callers 1

TestBodyRenameAttributeFunction · 0.80

Implementers 8

Bodyhclsyntax/structure.go
unknownBodyext/dynblock/unknown_body.go
expandBodyext/dynblock/expand_body.go
deepWrapperext/transform/transform.go
diagBodyext/transform/error.go
bodyjson/structure.go
mockBodyhcltest/mock.go

Calls 2

GetAttributeMethod · 0.95
setNameMethod · 0.80

Tested by 1

TestBodyRenameAttributeFunction · 0.64