MCPcopy
hub / github.com/go-task/task / UnmarshalYAML

Method UnmarshalYAML

taskfile/ast/vars.go:179–206  ·  view source on GitHub ↗
(node *yaml.Node)

Source from the content-addressed store, hash-verified

177}
178
179func (vs *Vars) UnmarshalYAML(node *yaml.Node) error {
180 if vs == nil || vs.om == nil {
181 *vs = *NewVars()
182 }
183 vs.om = orderedmap.NewOrderedMap[string, Var]()
184 switch node.Kind {
185 case yaml.MappingNode:
186 // NOTE: orderedmap does not have an unmarshaler, so we have to decode
187 // the map manually. We increment over 2 values at a time and assign
188 // them as a key-value pair.
189 for i := 0; i < len(node.Content); i += 2 {
190 keyNode := node.Content[i]
191 valueNode := node.Content[i+1]
192
193 // Decode the value node into a Task struct
194 var v Var
195 if err := valueNode.Decode(&v); err != nil {
196 return errors.NewTaskfileDecodeError(err, node)
197 }
198
199 // Add the task to the ordered map
200 vs.Set(keyNode.Value, v)
201 }
202 return nil
203 }
204
205 return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("vars")
206}

Callers

nothing calls this directly

Calls 4

SetMethod · 0.95
NewTaskfileDecodeErrorFunction · 0.92
NewVarsFunction · 0.85
WithTypeMessageMethod · 0.80

Tested by

no test coverage detected