blob: 6fb9e7259074a552dd4841237a6c3826aeb89635 (
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
28
29
30
31
32
|
package config
// Flag represents a nullable boolean value that is considered null until
// either parsed from YAML or merged in from another Flag value.
//
type Flag struct {
True bool
set bool
}
// UnmarshalYAML implements yaml.Unmarshaler to parse the underlying boolean
// value and detect that the Flag should no longer be considered null.
//
func (flag *Flag) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := unmarshal(&flag.True); err != nil {
return err
}
flag.set = true
return nil
}
// Merge takes another flag and, if set, merged its boolean value into this
// one.
//
func (flag *Flag) Merge(flag2 Flag) {
if flag2.set {
flag.True = flag2.True
flag.set = true
}
}
|