Tinkering with Viper to read configuration files

This commit is contained in:
raul 2024-05-16 09:30:48 +02:00
parent 4b17a74965
commit 21dc78fe4a
3 changed files with 12 additions and 10 deletions

View File

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

View File

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

View File

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