func initConfig() {
	if cfgFile != "" {
		viper.SetConfigFile(cfgFile)
	} else {
		basePath, err := os.Executable()
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		viper.AddConfigPath(path.Dir(basePath))
		viper.AddConfigPath(".")
		viper.SetConfigName("moleculer-config")
	}
	viper.AutomaticEnv()  
	if err := viper.ReadInConfig(); err == nil {
		fmt.Println("Using config file:", viper.ConfigFileUsed())
	} else {
		fmt.Println("Error loading config - Error: ", err)
	}
}
initConfig reads in config file and ENV variables if set.
package cmd
import (
	"fmt"
	"os"
	"path"
	"github.com/moleculer-go/moleculer"
	"github.com/moleculer-go/moleculer/broker"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)
var cfgFile string
var RootCmd = &cobra.Command{
	Use:   "mol",
	Short: "Moleculer Go CLI",
	Long:  `Moleculer CLI allows u to control the lifecycle of your service.`,
}
type RunOpts struct {
	Config       *moleculer.Config
	StartHandler func(*broker.ServiceBroker, *cobra.Command)
}
var UserOpts *RunOpts
func Execute(runOpts RunOpts) {
	UserOpts = &runOpts
	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 <app>/.moleculer-config.yaml)")
}