// Use of this source code is governed by MIT-style // license that can be found in the LICENSE file. package cmd import ( "github.com/spf13/cobra" homedir "github.com/mitchellh/go-homedir" "github.com/spf13/viper" ) var cfgFile string // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "goffee", Version: "v1.7.2", Short: "Goffee is the cli tool", Long: `Goffee is the cli tool for creating new projects and performing other tasks`, // Run: func(cmd *cobra.Command, args []string) { // }, } func Execute() { cobra.CheckErr(rootCmd.Execute()) } func init() { cobra.OnInitialize(initConfig) } // initConfig reads in config file and ENV variables if set. func initConfig() { if cfgFile != "" { // Use config file from the flag. viper.SetConfigFile(cfgFile) } else { // Find home directory. home, err := homedir.Dir() cobra.CheckErr(err) // Search config in home directory with name ".goffee" (without extension). viper.AddConfigPath(home) viper.SetConfigName(".goffee") } viper.AutomaticEnv() // read in environment variables that match }