Compare commits

...

3 Commits

3 changed files with 11 additions and 18 deletions

View File

@ -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
}

View File

@ -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)

View File

@ -24,12 +24,13 @@ func VersionCmd(args CmdArgs) (int, error) {
if GitCommit != "" {
fmt.Fprintf(&b, " revision: %s\n", GitCommit)
}
if BuildDate != "" {
fmt.Fprintf(&b, " build date: %s\n", BuildDate)
}
fmt.Fprintf(&b, " go version: %s\n", runtime.Version())
fmt.Fprintf(&b, " platform: %s\n", runtime.GOOS+"/"+runtime.GOARCH)
fmt.Fprintf(&b, " platform: %s/%s\n", runtime.GOOS, runtime.GOARCH)
fmt.Print(b.String())