github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/flag/color.go (about) 1 package flag 2 3 import ( 4 "strings" 5 6 flags "github.com/jessevdk/go-flags" 7 ) 8 9 type Color struct { 10 Color bool 11 } 12 13 func (Color) Complete(prefix string) []flags.Completion { 14 return completions([]string{"true", "false"}, prefix, false) 15 } 16 17 func (c *Color) UnmarshalFlag(val string) error { 18 switch strings.ToLower(val) { 19 case "true": 20 c.Color = true 21 case "false": 22 c.Color = false 23 default: 24 return &flags.Error{ 25 Type: flags.ErrRequired, 26 Message: `COLOR must be "true" or "false"`, 27 } 28 } 29 30 return nil 31 }