Delete substitution and fix delete setters

This commit is contained in:
Phani Teja Marupaka
2020-08-17 00:43:25 -07:00
parent 0d5552fca6
commit ca04c874f2
12 changed files with 799 additions and 169 deletions

View File

@@ -384,6 +384,23 @@ func (rn *RNode) Fields() ([]string, error) {
return fields, nil
}
// FieldRNodes returns the list of field key RNodes for a MappingNode.
// Returns an error for non-MappingNodes.
func (rn *RNode) FieldRNodes() ([]*RNode, error) {
if err := ErrorIfInvalid(rn, yaml.MappingNode); err != nil {
return nil, errors.Wrap(err)
}
var fields []*RNode
for i := 0; i < len(rn.Content()); i += 2 {
yNode := rn.Content()[i]
// for each key node in the input mapping node contents create equivalent rNode
rNode := &RNode{}
rNode.SetYNode(yNode)
fields = append(fields, rNode)
}
return fields, nil
}
// Field returns a fieldName, fieldValue pair for MappingNodes.
// Returns nil for non-MappingNodes.
func (rn *RNode) Field(field string) *MapNode {