From 7db00e6cd300f6206025867f1b3fd6368380010b Mon Sep 17 00:00:00 2001 From: Yakiyo Date: Wed, 23 Aug 2023 05:36:23 +0000 Subject: [PATCH] feat: better handling of config file --- config/init.go | 1 + config/read.go | 7 ++----- where/where.go | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/config/init.go b/config/init.go index 9ebae58..b6f0fa0 100644 --- a/config/init.go +++ b/config/init.go @@ -9,6 +9,7 @@ import ( func init() { v.SetConfigType("toml") v.SetConfigName("tilde") + v.AddConfigPath(where.Dir()) v.SetDefault("auto_update", true) v.SetDefault("log_level", "warn") diff --git a/config/read.go b/config/read.go index 19d935b..a9a3c76 100644 --- a/config/read.go +++ b/config/read.go @@ -1,21 +1,18 @@ package config import ( - "github.com/Yakiyo/tilde/where" "github.com/charmbracelet/log" "github.com/spf13/viper" ) // Read config file and handle error cases func Read(file string) { - if file == "" { - viper.SetConfigFile(where.Config()) - } else { + if file != "" { viper.SetConfigFile(file) } if err := viper.ReadInConfig(); err != nil { if _, ok := err.(viper.ConfigFileNotFoundError); ok { - log.Warn("Missing config file, switching to defaults. Consider using the `--seed-config` flag to generate the default config file") + log.Info("Missing config file, switching to defaults. Consider using the `--seed-config` flag to generate the default config file") } else { log.Fatal("Error when reading config file", "err", err) } diff --git a/where/where.go b/where/where.go index 81f14c3..ae232cb 100644 --- a/where/where.go +++ b/where/where.go @@ -45,7 +45,7 @@ func Index() string { return filepath.Join(Cache(), "index.json") } -// path to config.toml file located inside root dir +// path to default config.toml file located inside root dir func Config() string { return filepath.Join(Dir(), "tilde.toml") }