Tinkering with Viper to read configuration files
This commit is contained in:
parent
4b17a74965
commit
21dc78fe4a
11
cmd/root.go
11
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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue