diff options
Diffstat (limited to 'cmd/root.go')
-rw-r--r-- | cmd/root.go | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/cmd/root.go b/cmd/root.go index f1fba18..2c6ca56 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -20,8 +20,10 @@ package cmd import ( "os" + "fmt" "github.com/spf13/cobra" + "github.com/spf13/viper" ) var ( @@ -32,7 +34,29 @@ var ( var rootCmd = &cobra.Command{ Use: "macli", Short: "macli - Unofficial CLI-Based MyAnimeList Client.", - Long: "macli is an unofficial MyAnimeClient for use inside the terminal.", + Long: "macli is an unofficial MyAnimeList Client for use inside the terminal.", +} + +func init() { + viper.SetConfigName("macli") + viper.SetConfigType("yaml") + viper.AddConfigPath("$HOME/.config/macli") + viper.AddConfigPath("/etc/macli") + + // dont show error if file not found + // macli doesnt need a config file to work properly + if err := viper.ReadInConfig(); err != nil { + // error if config file found but has errors + if _, ok := err.(viper.ConfigFileNotFoundError); !ok { + fmt.Println("Error while reading macli config file:", err) + os.Exit(1) + } + } + + name := viper.Get("name").(map[string]interface{}) + + fmt.Println("Config File Contents:", name["last"]) + os.Exit(0) } func Execute() { |