From 21dc78fe4a7164d1a189ba7af3980265b7853bd2 Mon Sep 17 00:00:00 2001 From: raul Date: Thu, 16 May 2024 09:30:48 +0200 Subject: [PATCH] Tinkering with Viper to read configuration files --- cmd/root.go | 11 +++++------ cmd/tune.go | 7 +++++-- cmd/ui.go | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index e0c3278..42087d1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,10 +5,9 @@ package cmd import ( "fmt" - "os" - "github.com/spf13/cobra" "github.com/spf13/viper" + "os" ) var cfgFile string @@ -41,7 +40,7 @@ func init() { // Cobra supports persistent flags, which, if defined here, // will be global for your application. - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.tune.yaml)") + rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/config/tune.yaml)") // Cobra also supports local flags, which will only run // when this action is called directly. @@ -59,9 +58,9 @@ func initConfig() { cobra.CheckErr(err) // Search config in home directory with name ".tune" (without extension). - viper.AddConfigPath(home) - viper.SetConfigType("yaml") - viper.SetConfigName(".tune") + viper.AddConfigPath(home + "/.config") + viper.SetConfigType("toml") + viper.SetConfigName("tune") } viper.AutomaticEnv() // read in environment variables that match diff --git a/cmd/tune.go b/cmd/tune.go index d7bc37f..50efb94 100644 --- a/cmd/tune.go +++ b/cmd/tune.go @@ -3,10 +3,13 @@ package cmd import ( "fmt" - "github.com/ebitengine/oto/v3" + "github.com/spf13/viper" + //"github.com/ebitengine/oto/v3" ) func tune() { - fmt.Println() + fmt.Println("tune called") + title := viper.Get("title") + fmt.Println(title) } diff --git a/cmd/ui.go b/cmd/ui.go index 9546fce..a30eeac 100644 --- a/cmd/ui.go +++ b/cmd/ui.go @@ -1,9 +1,9 @@ package cmd import ( - "github.com/jroimartin/gocui" +// "github.com/jroimartin/gocui" ) func UI() { - g, err := gocui.NewGui() + //g, err := gocui.NewGui() }