Schema what-changed almost complete.

Perhaps the biggest and most complex of all the models to determine what has changed.
This commit is contained in:
Dave Shanley
2022-10-10 12:19:57 -04:00
parent b83e751aa7
commit 61beb3ea2a
7 changed files with 805 additions and 44 deletions

View File

@@ -240,7 +240,7 @@ func FindKeyNode(key string, nodes []*yaml.Node) (keyNode *yaml.Node, valueNode
return nil, nil
}
// FindKeyNodeFull is an overloaded version of FindKeyNode. Thins version however returns keys, labels and values.
// FindKeyNodeFull is an overloaded version of FindKeyNode. This version however returns keys, labels and values.
// generally different things are required from different node trees, so depending on what this function is looking at
// it will return different things.
func FindKeyNodeFull(key string, nodes []*yaml.Node) (keyNode *yaml.Node, labelNode *yaml.Node, valueNode *yaml.Node) {
@@ -267,6 +267,33 @@ func FindKeyNodeFull(key string, nodes []*yaml.Node) (keyNode *yaml.Node, labelN
return nil, nil, nil
}
// FindKeyNodeFullTop is an overloaded version of FindKeyNodeFull. This version only looks at the top
// level of the node and not the children.
func FindKeyNodeFullTop(key string, nodes []*yaml.Node) (keyNode *yaml.Node, labelNode *yaml.Node, valueNode *yaml.Node) {
for i := range nodes {
if i%2 == 0 && key == nodes[i].Value {
return nodes[i], nodes[i], nodes[i+1] // next node is what we need.
}
}
for q, v := range nodes {
if q%2 != 0 {
continue
}
if key == v.Value {
if IsNodeMap(v) {
if q+1 == len(v.Content) {
return v, v.Content[q], v.Content[q]
}
return v, v.Content[q], v.Content[q+1]
}
if IsNodeArray(v) {
return v, v.Content[q], v.Content[q]
}
}
}
return nil, nil, nil
}
type ExtensionNode struct {
Key *yaml.Node
Value *yaml.Node