MCPcopy Index your code
hub / github.com/go-task/task / UnmarshalYAML

Method UnmarshalYAML

taskfile/ast/for.go:19–62  ·  view source on GitHub ↗
(node *yaml.Node)

Source from the content-addressed store, hash-verified

17}
18
19func (f *For) UnmarshalYAML(node *yaml.Node) error {
20 switch node.Kind {
21
22 case yaml.ScalarNode:
23 var from string
24 if err := node.Decode(&from); err != nil {
25 return errors.NewTaskfileDecodeError(err, node)
26 }
27 f.From = from
28 return nil
29
30 case yaml.SequenceNode:
31 var list []any
32 if err := node.Decode(&list); err != nil {
33 return errors.NewTaskfileDecodeError(err, node)
34 }
35 f.List = list
36 return nil
37
38 case yaml.MappingNode:
39 var forStruct struct {
40 Matrix *Matrix
41 Var string
42 Split string
43 As string
44 }
45 if err := node.Decode(&forStruct); err != nil {
46 return errors.NewTaskfileDecodeError(err, node)
47 }
48 if forStruct.Var == "" && forStruct.Matrix.Len() == 0 {
49 return errors.NewTaskfileDecodeError(nil, node).WithMessage("invalid keys in for")
50 }
51 if forStruct.Var != "" && forStruct.Matrix.Len() != 0 {
52 return errors.NewTaskfileDecodeError(nil, node).WithMessage("cannot use both var and matrix in for")
53 }
54 f.Matrix = forStruct.Matrix
55 f.Var = forStruct.Var
56 f.Split = forStruct.Split
57 f.As = forStruct.As
58 return nil
59 }
60
61 return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("for")
62}
63
64func (f *For) DeepCopy() *For {
65 if f == nil {

Callers

nothing calls this directly

Calls 4

NewTaskfileDecodeErrorFunction · 0.92
WithMessageMethod · 0.80
WithTypeMessageMethod · 0.80
LenMethod · 0.45

Tested by

no test coverage detected