12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package gva
- import (
- "github.com/mitchellh/go-homedir"
- "os"
- "github.com/gookit/color"
- "github.com/spf13/cobra"
- "github.com/spf13/viper"
- )
- var cfgFile string
- var rootCmd = &cobra.Command{
- Use: "gva",
- Short: "这是一款amazing的终端工具",
- Long: `欢迎使用gva终端工具
- ________ ____ ____ _____
- / _____/ \ \ / / / _ \
- / \ ___ \ Y / / /_\ \
- \ \_\ \ \ / / | \
- \______ / \___/ \____|__ /
- \/ \/
- `,
-
-
-
- }
- func Execute() {
- if err := rootCmd.Execute(); err != nil {
- color.Warn.Println(err)
- os.Exit(1)
- }
- }
- func init() {
- cobra.OnInitialize(initConfig)
-
-
-
- rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.gva.yaml)")
-
-
- rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
- }
- func initConfig() {
- if cfgFile != "" {
-
- viper.SetConfigFile(cfgFile)
- } else {
-
- home, err := homedir.Dir()
- if err != nil {
- color.Warn.Println(err)
- os.Exit(1)
- }
-
- viper.AddConfigPath(home)
- viper.SetConfigName(".gva")
- }
- viper.AutomaticEnv()
-
- if err := viper.ReadInConfig(); err == nil {
- color.Warn.Println("Using config file:", viper.ConfigFileUsed())
- }
- }
|