github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+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  }