From 7f351e0874b1a05931cfdd2c92819ea06a6b0a1b Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 23 Mar 2020 13:18:46 +0100 Subject: [PATCH] Fix startup failure when home directory doesn't exist --- cmd/root.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index e2841a5ce..c33787b98 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -75,15 +75,12 @@ func initConfig() { // Use config file from the flag viper.SetConfigFile(cfgFile) } else { - // Find home directory - home, err := os.UserHomeDir() - if err != nil { - fmt.Println(err) - os.Exit(1) + // Search for config in home directory if available + if home, err := os.UserHomeDir(); err == nil { + viper.AddConfigPath(home) } // Search config in home directory with name "mbmd" (without extension). - viper.AddConfigPath(home) viper.AddConfigPath(".") // optionally look for config in the working directory viper.AddConfigPath("/etc") // path to look for the config file in