2017-06-30 21:10:25 +05:30
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2018-01-24 04:09:40 +05:30
|
|
|
"elyby/minecraft-skinsystem/bootstrap"
|
|
|
|
|
2017-06-30 21:10:25 +05:30
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
var cfgFile string
|
|
|
|
|
|
|
|
var RootCmd = &cobra.Command{
|
2018-01-24 04:09:40 +05:30
|
|
|
Use: "",
|
|
|
|
Short: "Nothing here",
|
|
|
|
Version: bootstrap.GetVersion(),
|
2017-06-30 21:10:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
|
|
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
|
|
|
func Execute() {
|
|
|
|
if err := RootCmd.Execute(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 04:09:40 +05:30
|
|
|
func init() {
|
2017-06-30 21:10:25 +05:30
|
|
|
cobra.OnInitialize(initConfig)
|
|
|
|
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.test.yaml)")
|
|
|
|
}
|
|
|
|
|
|
|
|
func initConfig() {
|
|
|
|
if cfgFile != "" {
|
|
|
|
viper.SetConfigFile(cfgFile)
|
2017-09-03 02:39:11 +05:30
|
|
|
} else {
|
|
|
|
viper.SetConfigName("config")
|
2017-09-04 22:54:55 +05:30
|
|
|
viper.AddConfigPath("/etc/minecraft-skinsystem")
|
2017-09-03 02:39:11 +05:30
|
|
|
viper.AddConfigPath(".")
|
2017-06-30 21:10:25 +05:30
|
|
|
}
|
|
|
|
|
2017-08-15 03:13:31 +05:30
|
|
|
viper.AutomaticEnv()
|
2017-06-30 21:10:25 +05:30
|
|
|
|
|
|
|
if err := viper.ReadInConfig(); err == nil {
|
2018-01-16 02:22:22 +05:30
|
|
|
// TODO: show only on verbose mode
|
2017-06-30 21:10:25 +05:30
|
|
|
fmt.Println("Using config file:", viper.ConfigFileUsed())
|
|
|
|
}
|
|
|
|
}
|