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

Method UnmarshalYAML

taskfile/ast/include.go:118–147  ·  view source on GitHub ↗

UnmarshalYAML implements the yaml.Unmarshaler interface.

(node *yaml.Node)

Source from the content-addressed store, hash-verified

116
117// UnmarshalYAML implements the yaml.Unmarshaler interface.
118func (includes *Includes) UnmarshalYAML(node *yaml.Node) error {
119 if includes == nil || includes.om == nil {
120 *includes = *NewIncludes()
121 }
122 switch node.Kind {
123 case yaml.MappingNode:
124 // NOTE: orderedmap does not have an unmarshaler, so we have to decode
125 // the map manually. We increment over 2 values at a time and assign
126 // them as a key-value pair.
127 for i := 0; i < len(node.Content); i += 2 {
128 keyNode := node.Content[i]
129 valueNode := node.Content[i+1]
130
131 // Decode the value node into an Include struct
132 var v Include
133 if err := valueNode.Decode(&v); err != nil {
134 return errors.NewTaskfileDecodeError(err, node)
135 }
136
137 // Set the include namespace
138 v.Namespace = keyNode.Value
139
140 // Add the include to the ordered map
141 includes.Set(keyNode.Value, &v)
142 }
143 return nil
144 }
145
146 return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("includes")
147}
148
149func (include *Include) UnmarshalYAML(node *yaml.Node) error {
150 switch node.Kind {

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected