func initConfig() {
	if cfgFile != "" {
		viper.SetConfigFile(cfgFile)
	} else {
		home, err := homedir.Dir()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		viper.AddConfigPath(home)
		viper.SetConfigName(".alfred")
	}
	viper.AutomaticEnv()  
	if err := viper.ReadInConfig(); err == nil {
		fmt.Println("Using config file:", viper.ConfigFileUsed())
	}
}
initConfig reads in config file and ENV variables if set.
package cmd
import (
	"fmt"
	"os"
	homedir "github.com/mitchellh/go-homedir"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)
const (
	configPerm = 0600
)
var cfgFile string
var RootCmd = &cobra.Command{
	Use:   "alfred",
	Short: "A stellar wallet",
	Long:  `A stellar wallet`,
}
func Execute() {
	if err := RootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
func init() {
	cobra.OnInitialize(initConfig)
	RootCmd.PersistentFlags().StringP("secret", "s", "", "secret used for encryption of the wallet")
	RootCmd.PersistentFlags().StringP("db", "d", "alfred.yaml", "path of file where everything will be stored")
	RootCmd.PersistentFlags().Bool("testnet", false, "use testnet")
	RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.alfred.yaml)")
	viper.BindPFlags(RootCmd.PersistentFlags())
	viper.BindPFlags(RootCmd.Flags())
}