Skip to content

Commit

Permalink
feat: init configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakiyo committed Aug 23, 2023
1 parent 8742bd1 commit a1b2712
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions config/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package config

import (
"github.com/Yakiyo/tilde/where"
v "github.com/spf13/viper"
)

func init() {
v.SetConfigType("toml")
v.SetConfigName("tilde.toml")

// to be used when setting values from cli
v.RegisterAlias("tilde_dir", "dir")

v.SetDefault("auto_update", true)
v.SetDefault("log_level", "warn")
v.SetDefault("tilde_dir", where.Dir())
v.SetDefault("colors", "auto")
}
17 changes: 17 additions & 0 deletions config/read.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package config

import (
"github.com/charmbracelet/log"
"github.com/spf13/viper"
)

// Read config file and handle error cases
func Read() {
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")
} else {
log.Fatal("Error when reading config file", "err", err)
}
}
}

0 comments on commit a1b2712

Please # to comment.