Add mkflex command

This commit is contained in:
Dan Jones 2025-07-16 11:40:25 -05:00
commit f4497aef7e
7 changed files with 333 additions and 1 deletions

45
types/yaml.go Normal file
View file

@ -0,0 +1,45 @@
package types
import "gopkg.in/yaml.v3"
type YamlTypeError struct {
Node *yaml.Node
}
func (ye *YamlTypeError) Error() string {
return ye.Node.Tag + " is not a valid type for this field"
}
type IntOrString struct {
intVal int
strVal string
isInt bool
}
func (is IntOrString) MarshalYAML() (any, error) {
if is.isInt {
return is.intVal, nil
}
return is.strVal, nil
}
func (is *IntOrString) UnmarshalYAML(value *yaml.Node) error {
if value.Tag == `!!int` {
is.isInt = true
return value.Decode(&is.intVal)
}
if value.Tag == `!!str` {
is.isInt = false
return value.Decode(&is.strVal)
}
return &YamlTypeError{Node: value}
}
func (is IntOrString) IsZero() bool {
if is.isInt {
return is.intVal == 0
}
return is.strVal == ""
}