@@ -119,20 +119,41 @@ func applyToNode(node *yaml.RNode, value *yaml.RNode, target *types.TargetSelect
119
119
if target .Options != nil && target .Options .Create {
120
120
t , err = node .Pipe (yaml .LookupCreate (value .YNode ().Kind , fieldPath ... ))
121
121
} else {
122
- t , err = node .Pipe (yaml .Lookup ( fieldPath ... ) )
122
+ t , err = node .Pipe (& yaml.PathMatcher { Path : fieldPath } )
123
123
}
124
124
if err != nil {
125
125
return err
126
126
}
127
127
if t != nil {
128
- if err = setTargetValue (target .Options , t , value ); err != nil {
128
+ if err = applyToOneNode (target .Options , t , value ); err != nil {
129
129
return err
130
130
}
131
131
}
132
132
}
133
133
return nil
134
134
}
135
135
136
+ func applyToOneNode (options * types.FieldOptions , t * yaml.RNode , value * yaml.RNode ) error {
137
+ if len (t .YNode ().Content ) == 0 {
138
+ if err := setTargetValue (options , t , value ); err != nil {
139
+ return err
140
+ }
141
+ return nil
142
+ }
143
+
144
+ for _ , scalarNode := range t .YNode ().Content {
145
+ if options != nil && options .Create {
146
+ return fmt .Errorf ("cannot use create option in a multi-value target" )
147
+ }
148
+ rn := yaml .NewRNode (scalarNode )
149
+ if err := setTargetValue (options , rn , value ); err != nil {
150
+ return err
151
+ }
152
+ }
153
+
154
+ return nil
155
+ }
156
+
136
157
func setTargetValue (options * types.FieldOptions , t * yaml.RNode , value * yaml.RNode ) error {
137
158
value = value .Copy ()
138
159
if options != nil && options .Delimiter != "" {
@@ -152,7 +173,9 @@ func setTargetValue(options *types.FieldOptions, t *yaml.RNode, value *yaml.RNod
152
173
}
153
174
value .YNode ().Value = strings .Join (tv , options .Delimiter )
154
175
}
176
+
155
177
t .SetYNode (value .YNode ())
178
+
156
179
return nil
157
180
}
158
181
0 commit comments