(node *yaml.Node)
| 109 | } |
| 110 | |
| 111 | func (matrix *Matrix) UnmarshalYAML(node *yaml.Node) error { |
| 112 | switch node.Kind { |
| 113 | case yaml.MappingNode: |
| 114 | // NOTE: orderedmap does not have an unmarshaler, so we have to decode |
| 115 | // the map manually. We increment over 2 values at a time and assign |
| 116 | // them as a key-value pair. |
| 117 | for i := 0; i < len(node.Content); i += 2 { |
| 118 | keyNode := node.Content[i] |
| 119 | valueNode := node.Content[i+1] |
| 120 | |
| 121 | switch valueNode.Kind { |
| 122 | case yaml.SequenceNode: |
| 123 | // Decode the value node into a Matrix struct |
| 124 | var v []any |
| 125 | if err := valueNode.Decode(&v); err != nil { |
| 126 | return errors.NewTaskfileDecodeError(err, node) |
| 127 | } |
| 128 | |
| 129 | // Add the row to the ordered map |
| 130 | matrix.Set(keyNode.Value, &MatrixRow{ |
| 131 | Value: v, |
| 132 | }) |
| 133 | |
| 134 | case yaml.MappingNode: |
| 135 | // Decode the value node into a Matrix struct |
| 136 | var refStruct struct { |
| 137 | Ref string |
| 138 | } |
| 139 | if err := valueNode.Decode(&refStruct); err != nil { |
| 140 | return errors.NewTaskfileDecodeError(err, node) |
| 141 | } |
| 142 | |
| 143 | // Add the reference to the ordered map |
| 144 | matrix.Set(keyNode.Value, &MatrixRow{ |
| 145 | Ref: refStruct.Ref, |
| 146 | }) |
| 147 | |
| 148 | default: |
| 149 | return errors.NewTaskfileDecodeError(nil, node).WithMessage("matrix values must be an array or a reference") |
| 150 | } |
| 151 | } |
| 152 | return nil |
| 153 | } |
| 154 | |
| 155 | return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("matrix") |
| 156 | } |
nothing calls this directly
no test coverage detected