Don't fail if config file isnot found

This commit is contained in:
Deluan 2020-07-03 09:39:28 -04:00
parent 99e269208e
commit ef9af6ed1a
2 changed files with 5 additions and 10 deletions

View File

@ -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)
}
}

View File

@ -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()
}