|
|
|
@ -35,6 +35,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() |
|
|
|
|
} |
|
|
|
@ -53,8 +56,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 |
|
|
|
|
} |
|
|
|
@ -72,14 +85,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 |
|
|
|
|
} |
|
|
|
|