diff --git a/.lumerc.sample b/.lumerc.sample new file mode 100644 index 0000000..6d10d6c --- /dev/null +++ b/.lumerc.sample @@ -0,0 +1 @@ +AccessToken = "token" \ No newline at end of file diff --git a/cmd/lume/__debug_bin b/cmd/lume/__debug_bin new file mode 100644 index 0000000..8b76317 Binary files /dev/null and b/cmd/lume/__debug_bin differ diff --git a/cmd/lume/main.go b/cmd/lume/main.go index bd56a0d..ec86572 100644 --- a/cmd/lume/main.go +++ b/cmd/lume/main.go @@ -24,9 +24,9 @@ func main() { defer windows.SetConsoleMode(stdout, originalMode) var config lumecmd.Config - homeDir, err := os.UserHomeDir() - _, err = toml.DecodeFile(path.Join(homeDir, lumercFile), &config) - if os.IsNotExist(err) { + config = loadConfig() + + if config.AccessToken == "" { config.AccessToken = os.Getenv("LIFX_ACCESS_TOKEN") } @@ -61,3 +61,30 @@ func main() { } os.Exit(exitCode) } + +func loadConfig() lumecmd.Config { + var config lumecmd.Config + var tryPath, configPath string + + homeDir, err := os.UserHomeDir() + if err == nil { + tryPath = path.Join(homeDir, lumercFile) + if _, err := os.Stat(tryPath); !os.IsNotExist(err) { + configPath = tryPath + } + } + + cwd, err := os.Getwd() + if err == nil { + tryPath = path.Join(cwd, lumercFile) + if _, err := os.Stat(tryPath); !os.IsNotExist(err) { + configPath = tryPath + } + } + + if configPath != "" { + toml.DecodeFile(configPath, &config) + } + + return config +}