diff --git a/cmd/config.go b/cmd/config.go index cb708bc..9e3eeff 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -60,6 +60,13 @@ func (c *Config) validateColors() (err error) { return err } +func (c *Config) MergeWithEnv() { + envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN") + if envAccessToken != "" { + c.AccessToken = envAccessToken + } +} + func LoadConfig(s string) (*Config, error) { var err error var c *Config = &Config{} @@ -70,11 +77,6 @@ func LoadConfig(s string) (*Config, error) { err = fmt.Errorf("fatal: failed to parse; %w", err) } - envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN") - if envAccessToken != "" { - c.AccessToken = envAccessToken - } - return c, err } @@ -89,11 +91,6 @@ func LoadConfigFile(configPath string) (*Config, error) { err = fmt.Errorf("fatal: failed to parse %s; %w", configPath, err) } - envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN") - if envAccessToken != "" { - c.AccessToken = envAccessToken - } - return c, err } diff --git a/cmd/main.go b/cmd/main.go index 547f12d..ae986a4 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -4,7 +4,6 @@ import ( "errors" "flag" "fmt" - "os" "git.kill0.net/chill9/lifx-go" ) @@ -43,11 +42,7 @@ func Main(args []string) (int, error) { if config, err = LoadConfigFile(configPath); err != nil { return ExitFailure, err } - - envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN") - if envAccessToken != "" { - config.AccessToken = envAccessToken - } + config.MergeWithEnv() if err = config.Validate(); err != nil { return ExitFailure, fmt.Errorf("fatal: %s", err) @@ -87,4 +82,4 @@ func Main(args []string) (int, error) { } return exitCode, err -} \ No newline at end of file +}