github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/internal/cmd/subcmds/lint/autoDisableFlag.go (about) 1 package lint 2 3 import ( 4 "fmt" 5 6 "github.com/yoheimuta/protolint/linter/autodisable" 7 ) 8 9 type autoDisableFlag struct { 10 raw string 11 autoDisableType autodisable.PlacementType 12 } 13 14 func (f *autoDisableFlag) String() string { 15 return fmt.Sprint(f.raw) 16 } 17 18 func (f *autoDisableFlag) Set(value string) error { 19 if f.autoDisableType != 0 { 20 return fmt.Errorf("auto_disable is already set") 21 } 22 23 r, err := GetAutoDisableType(value) 24 if err != nil { 25 return err 26 } 27 f.raw = value 28 f.autoDisableType = r 29 return nil 30 } 31 32 // GetAutoDisableType returns a type from the specified key. 33 func GetAutoDisableType(value string) (autodisable.PlacementType, error) { 34 rs := map[string]autodisable.PlacementType{ 35 "next": autodisable.Next, 36 "this": autodisable.ThisThenNext, 37 } 38 if r, ok := rs[value]; ok { 39 return r, nil 40 } 41 return autodisable.Noop, fmt.Errorf(`available auto_disable are "next" and "this"`) 42 }