goaegis/cmd/goaegis/enum_value.go
Dawid Wysokiński 5531dcf084
All checks were successful
ci/woodpecker/push/test Pipeline was successful
init
2024-04-21 12:21:42 +02:00

31 lines
445 B
Go

package main
import (
"fmt"
"strings"
)
type EnumValue struct {
Enum []string
Default string
selected string
}
func (e *EnumValue) Set(value string) error {
for _, enum := range e.Enum {
if enum == value {
e.selected = value
return nil
}
}
return fmt.Errorf("allowed values are %s", strings.Join(e.Enum, ", "))
}
func (e *EnumValue) String() string {
if e.selected == "" {
return e.Default
}
return e.selected
}