From 78ede4a08467b4aa767c9dca7b52253f06785676 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sun, 24 Jan 2021 19:02:48 -0600 Subject: [PATCH] Validate colors from configuration file --- cmd/command.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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 }