Get the values of a mapping node
pantelis-karamolegkos opened this issue · comments
Pantelis Karamolegkos commented
Is your feature request related to a problem? Please describe.
I want to be able to get the values of a (say mapping) node, including comments.
Describe the solution you'd like
Let's say for example we have the following yaml
apiVersion: helm.toolkit.fluxcd.io/v2beta1
kind: HelmRelease
metadata:
name: myapp
namespace: default
spec:
chart:
spec:
# THIS IS A COMMENT
chart: charts/myapp
reconcileStrategy: Revision
sourceRef:
kind: GitRepository
name: my-branch
namespace: systems
I want to be able to do something like the following:
(assume file
is an *os.File
with the above contents)
path, err := yaml.PathString("$.spec.chart")
node, err := path.ReadNode(file)
contents := node.GetContents() // or node.GetChildren() or whatever
fmt.Println(contents)
result
# THIS IS A COMMENT
chart: charts/myapp
reconcileStrategy: Revision
sourceRef:
kind: GitRepository
name: my-branch
namespace: systems
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.