don't exit when current user is unknown (#14)

This commit is contained in:
饺子w
2019-03-29 09:36:22 +08:00
committed by GitHub
parent 439f43e91a
commit 4319a0aea4

View File

@@ -4,25 +4,17 @@ import (
"os/user"
"path/filepath"
"runtime"
"github.com/gotify/cli/utils"
)
func userDir() string {
usr, err := user.Current()
if err != nil {
utils.Exit1With(err)
}
return usr.HomeDir
}
func GetLocations() (res []string) {
res = append(res, "./cli.json")
func GetLocations() []string {
inUserDir := filepath.Join(userDir(), ".gotify", "cli.json")
etcPath := "/etc/gotify/cli.json"
relativePath := "./cli.json"
if runtime.GOOS == "windows" {
return []string{relativePath, inUserDir}
} else {
return []string{relativePath, inUserDir, etcPath}
if usr, err := user.Current(); err != nil {
res = append(res, filepath.Join(usr.HomeDir, ".gotify", "cli.json"))
}
if runtime.GOOS != "windows" {
res = append(res, "/etc/gotify/cli.json")
}
return
}