diff --git a/cmd/command.go b/cmd/command.go index ab0e0fa..c8b0c6b 100644 --- a/cmd/command.go +++ b/cmd/command.go @@ -100,5 +100,31 @@ func (c *Config) Validate() error { if c.AccessToken == "" { err = errors.New("access_token is not set") } + + if err = c.validateColors(); err != nil { + return err + } + + return err +} + +func (c *Config) validateColors() (err error) { + if len(c.Colors) > 0 { + for name, hsb := range c.Colors { + if len(hsb) != 3 { + return fmt.Errorf("color '%s' needs three values", name) + } + h, s, b := hsb[0], hsb[1], hsb[2] + if h < 0 || h > 360 { + return fmt.Errorf("color '%s' hue value must be between 0.0-360.0", name) + } + if s < 0 || b > 1 { + return fmt.Errorf("color '%s' saturation value must be between 0.0-1.0", name) + } + if b < 0 || b > 1 { + return fmt.Errorf("color '%s' brightness value must be between 0.0-1.0", name) + } + } + } return err }