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

Method UnmarshalYAML

taskfile/ast/tasks.go:211–244  ·  view source on GitHub ↗
(node *yaml.Node)

Source from the content-addressed store, hash-verified

209}
210
211func (t *Tasks) UnmarshalYAML(node *yaml.Node) error {
212 if t == nil || t.om == nil {
213 *t = *NewTasks()
214 }
215 switch node.Kind {
216 case yaml.MappingNode:
217 // NOTE: orderedmap does not have an unmarshaler, so we have to decode
218 // the map manually. We increment over 2 values at a time and assign
219 // them as a key-value pair.
220 for i := 0; i < len(node.Content); i += 2 {
221 keyNode := node.Content[i]
222 valueNode := node.Content[i+1]
223
224 // Decode the value node into a Task struct
225 var v Task
226 if err := valueNode.Decode(&v); err != nil {
227 return errors.NewTaskfileDecodeError(err, node)
228 }
229
230 // Set the task name and location
231 v.Task = keyNode.Value
232 v.Location = &Location{
233 Line: keyNode.Line,
234 Column: keyNode.Column,
235 }
236
237 // Add the task to the ordered map
238 t.Set(keyNode.Value, &v)
239 }
240 return nil
241 }
242
243 return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("tasks")
244}
245
246func taskNameWithNamespace(taskName string, namespace string) string {
247 if after, ok := strings.CutPrefix(taskName, NamespaceSeparator); ok {

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected