1
0
Fork 0
forked from goffee/goffee
goffee/cmd/root.go

50 lines
1.1 KiB
Go

// 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.3",
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
}