diff --git a/main/main.go b/main/main.go index 50b33343..6ed012ae 100644 --- a/main/main.go +++ b/main/main.go @@ -47,6 +47,9 @@ func fileExists(file string) bool { } func dirExists(file string) bool { + if file == "" { + return false + } info, err := os.Stat(file) return err == nil && info.IsDir() } @@ -65,8 +68,18 @@ func readConfDir(dirPath string) { func getConfigFilePath() (cmdarg.Arg, error) { if dirExists(configDir) { + log.Println("Using confdir from arg:", configDir) readConfDir(configDir) + } else { + if envConfDir := platform.GetConfDirPath(); dirExists(envConfDir) { + log.Println("Using confdir from env:", envConfDir) + readConfDir(envConfDir) + if len(configFiles) > 0 { + return configFiles, nil + } + } } + if len(configFiles) > 0 { return configFiles, nil } @@ -84,14 +97,6 @@ func getConfigFilePath() (cmdarg.Arg, error) { return cmdarg.Arg{configFile}, nil } - if envConfDir := platform.GetConfDirPath(); dirExists(envConfDir) { - log.Println("Using confdir from env: ", envConfDir) - readConfDir(envConfDir) - if len(configFiles) > 0 { - return configFiles, nil - } - } - log.Println("Using config from STDIN") return cmdarg.Arg{"stdin:"}, nil }