aboutsummaryrefslogtreecommitdiff
path: root/internal/behavior/desc.go
blob: ca4bf699528ca99f45cad4f8b00d5595ee3259be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package behavior

import "gopkg.in/yaml.v3"

type DescVariant struct {
	Text      string     `yaml:"text"`
	Condition *Condition `yaml:"condition,omitempty"`
}

type DescList []DescVariant

func (dl *DescList) UnmarshalYAML(value *yaml.Node) error {
	if value.Kind == yaml.ScalarNode {
		var s string
		if err := value.Decode(&s); err != nil {
			return err
		}
		*dl = DescList{{Text: s}}
		return nil
	}
	var entries []DescVariant
	if err := value.Decode(&entries); err != nil {
		return err
	}
	*dl = entries
	return nil
}