handle unknown home gracefully

main
gapodo 2023-11-25 20:57:27 +01:00
parent 7d4b9549fa
commit 6da9e7a17d
1 changed files with 5 additions and 3 deletions

View File

@ -10,7 +10,6 @@ import (
"git.kle.li/tools/go-import-redirector/pkg/configuration/file"
"git.kle.li/tools/go-import-redirector/pkg/packagelist"
"github.com/fsnotify/fsnotify"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
@ -33,9 +32,12 @@ func New(cfgFile string, hotReload bool, reloadFunction func()) *Configuration {
} else {
// Find home directory.
home, err := os.UserHomeDir()
cobra.CheckErr(err)
if err == nil {
c.v.AddConfigPath(home)
} else {
fmt.Println("Unable to determine $HOME, not searching it for potential config")
}
c.v.AddConfigPath(home)
c.v.AddConfigPath("/etc/")
c.v.AddConfigPath(".")
c.v.SetConfigType("yaml")