diff --git a/cmd/root.go b/cmd/root.go index 76e45f767..977cf7068 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -52,7 +52,9 @@ func startServer() { // TODO: Implemement some struct tags to map flags to viper func init() { - cobra.OnInitialize(initConfig) + cobra.OnInitialize(func() { + conf.InitConfig(cfgFile) + }) rootCmd.PersistentFlags().StringVarP(&cfgFile, "configfile", "c", "", `config file (default "./navidrome.toml")`) rootCmd.PersistentFlags().String("musicfolder", viper.GetString("musicfolder"), "folder where your music is stored") @@ -81,10 +83,3 @@ func init() { _ = viper.BindPFlag("transcodingcachesize", rootCmd.Flags().Lookup("transcodingcachesize")) _ = viper.BindPFlag("imagecachesize", rootCmd.Flags().Lookup("imagecachesize")) } - -func initConfig() { - if err := conf.InitConfig(cfgFile); err != nil { - fmt.Printf("Error loading config file '%s'. Error: %s\n", viper.ConfigFileUsed(), err) - os.Exit(1) - } -} diff --git a/conf/configuration.go b/conf/configuration.go index 22de44ffe..fa8b1bf41 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -84,7 +84,7 @@ func init() { viper.SetDefault("devautocreateadminpassword", "") } -func InitConfig(cfgFile string) error { +func InitConfig(cfgFile string) { if cfgFile != "" { // Use config file from the flag. viper.SetConfigFile(cfgFile) @@ -98,5 +98,5 @@ func InitConfig(cfgFile string) error { viper.SetEnvPrefix("ND") viper.AutomaticEnv() - return viper.ReadInConfig() + viper.ReadInConfig() }