-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve the eibc client setup verbosity (#834)
- Loading branch information
1 parent
f57617d
commit db99b6c
Showing
4 changed files
with
172 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package yamlconfig | ||
|
||
import ( | ||
"fmt" | ||
|
||
yaml "gopkg.in/yaml.v3" | ||
) | ||
|
||
func UpdateNestedYAML(node *yaml.Node, path []string, value string) error { | ||
if len(path) == 0 { | ||
node.Value = value | ||
return nil | ||
} | ||
|
||
if node.Kind != yaml.MappingNode { | ||
return fmt.Errorf("expected a mapping node, got %v", node.Kind) | ||
} | ||
|
||
for i := 0; i < len(node.Content); i += 2 { | ||
if node.Content[i].Value == path[0] { | ||
return UpdateNestedYAML(node.Content[i+1], path[1:], value) | ||
} | ||
} | ||
|
||
return fmt.Errorf("path not found: %v", path[0]) | ||
} | ||
|
||
func PrintYAMLStructure(node *yaml.Node, indent string) { | ||
switch node.Kind { | ||
case yaml.DocumentNode: | ||
for _, n := range node.Content { | ||
PrintYAMLStructure(n, indent) | ||
} | ||
case yaml.MappingNode: | ||
fmt.Printf("%sMapping:\n", indent) | ||
for i := 0; i < len(node.Content); i += 2 { | ||
fmt.Printf("%s %s:\n", indent, node.Content[i].Value) | ||
PrintYAMLStructure(node.Content[i+1], indent+" ") | ||
} | ||
case yaml.SequenceNode: | ||
fmt.Printf("%sSequence:\n", indent) | ||
for _, n := range node.Content { | ||
PrintYAMLStructure(n, indent+" ") | ||
} | ||
case yaml.ScalarNode: | ||
fmt.Printf("%sScalar: %s\n", indent, node.Value) | ||
} | ||
} |