Compare commits

..

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

View File

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