Compare commits

..

No commits in common. "73123d0806623712b04dfe69214e83e195df0c3b" and "667b1cf288d135d21c69502f82ea70b76ace9990" have entirely different histories.

View File

@ -11,21 +11,14 @@ import (
"github.com/BurntSushi/toml"
)
const lumercFile string = ".lumerc"
const lumercFile = ".lumerc"
func main() {
var config lumecmd.Config
config = loadConfig()
configPath := getConfigPath()
if _, err := toml.DecodeFile(configPath, &config); err != nil {
fmt.Printf("fatal: failed to parse %s\n", configPath)
fmt.Println(err)
os.Exit(1)
}
envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN")
if envAccessToken != "" {
config.AccessToken = envAccessToken
if config.AccessToken == "" {
config.AccessToken = os.Getenv("LIFX_ACCESS_TOKEN")
}
if config.AccessToken == "" {
@ -52,7 +45,7 @@ func main() {
fs := cmd.Flags
fs.Parse(os.Args[2:])
cmdArgs.Flags = lumecmd.Flags{FlagSet: fs}
cmdArgs.Flags = lumecmd.Flags{fs}
exitCode, err := cmd.Func(cmdArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "fatal: %s\n", err)
@ -60,10 +53,10 @@ func main() {
os.Exit(exitCode)
}
func getConfigPath() string {
func loadConfig() lumecmd.Config {
var config lumecmd.Config
var tryPath, configPath string
// ~/.lumerc
homeDir, err := os.UserHomeDir()
if err == nil {
tryPath = path.Join(homeDir, lumercFile)
@ -72,7 +65,6 @@ func getConfigPath() string {
}
}
// ./.lumerc
cwd, err := os.Getwd()
if err == nil {
tryPath = path.Join(cwd, lumercFile)
@ -81,5 +73,9 @@ func getConfigPath() string {
}
}
return configPath
if configPath != "" {
toml.DecodeFile(configPath, &config)
}
return config
}