1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-17 21:18:31 +02:00

Extract a lookupKey function that will be useful in the next commit

This commit is contained in:
Stefan Haller 2023-06-08 09:55:23 +02:00
parent 4461dc68b7
commit 9cbd7fe69e

View File

@ -57,10 +57,8 @@ func updateYamlNode(node *yaml.Node, path []string, value string) error {
}
key := path[0]
for i := 0; i < len(node.Content)-1; i += 2 {
if node.Content[i].Value == key {
return updateYamlNode(node.Content[i+1], path[1:], value)
}
if _, valueNode := lookupKey(node, key); valueNode != nil {
return updateYamlNode(valueNode, path[1:], value)
}
// if the key doesn't exist, we'll add it
@ -87,3 +85,13 @@ func updateYamlNode(node *yaml.Node, path []string, value string) error {
}, newNode)
return updateYamlNode(newNode, path[1:], value)
}
func lookupKey(node *yaml.Node, key string) (*yaml.Node, *yaml.Node) {
for i := 0; i < len(node.Content)-1; i += 2 {
if node.Content[i].Value == key {
return node.Content[i], node.Content[i+1]
}
}
return nil, nil
}