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 return err
} }
func (c *Config) MergeWithEnv() {
envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN")
if envAccessToken != "" {
c.AccessToken = envAccessToken
}
}
func LoadConfig(s string) (*Config, error) { func LoadConfig(s string) (*Config, error) {
var err error var err error
var c *Config = &Config{} var c *Config = &Config{}
@ -70,11 +77,6 @@ func LoadConfig(s string) (*Config, error) {
err = fmt.Errorf("fatal: failed to parse; %w", err) err = fmt.Errorf("fatal: failed to parse; %w", err)
} }
envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN")
if envAccessToken != "" {
c.AccessToken = envAccessToken
}
return c, err return c, err
} }
@ -89,11 +91,6 @@ func LoadConfigFile(configPath string) (*Config, error) {
err = fmt.Errorf("fatal: failed to parse %s; %w", configPath, err) 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 return c, err
} }

View File

@ -4,7 +4,6 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"os"
"git.kill0.net/chill9/lifx-go" "git.kill0.net/chill9/lifx-go"
) )
@ -43,11 +42,7 @@ func Main(args []string) (int, error) {
if config, err = LoadConfigFile(configPath); err != nil { if config, err = LoadConfigFile(configPath); err != nil {
return ExitFailure, err return ExitFailure, err
} }
config.MergeWithEnv()
envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN")
if envAccessToken != "" {
config.AccessToken = envAccessToken
}
if err = config.Validate(); err != nil { if err = config.Validate(); err != nil {
return ExitFailure, fmt.Errorf("fatal: %s", err) return ExitFailure, fmt.Errorf("fatal: %s", err)
@ -87,4 +82,4 @@ func Main(args []string) (int, error) {
} }
return exitCode, err return exitCode, err
} }

View File

@ -24,12 +24,13 @@ func VersionCmd(args CmdArgs) (int, error) {
if GitCommit != "" { if GitCommit != "" {
fmt.Fprintf(&b, " revision: %s\n", GitCommit) fmt.Fprintf(&b, " revision: %s\n", GitCommit)
} }
if BuildDate != "" { if BuildDate != "" {
fmt.Fprintf(&b, " build date: %s\n", BuildDate) fmt.Fprintf(&b, " build date: %s\n", BuildDate)
} }
fmt.Fprintf(&b, " go version: %s\n", runtime.Version()) 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()) fmt.Print(b.String())