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(".cvscope")
	}
	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"
	"gocv.io/x/gocv"
	homedir "github.com/mitchellh/go-homedir"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)
var (
	cfgFile     string
	videoSource string
	window      *gocv.Window
	pause       bool
)
var rootCmd = &cobra.Command{
	Use:   "cvscope",
	Short: "Let's you visualize OpenCV filters and algorithms",
	Long: `CVscope is a command line tool for OpenCV that lets you visually explore various 
filters and algorithms for computer vision.
It can also generate Go code for the current filter command using the GoCV
programming library. CVscope is itself written using GoCV.`,
}
func Execute() {
	if err := rootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
func init() {
	cobra.OnInitialize(initConfig)
	rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cvscope.yaml)")
	rootCmd.PersistentFlags().StringVarP(&videoSource, "source", "f", "0", "video source, can be device number, file, or stream.")
}