-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
68 lines (54 loc) · 1.21 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"log"
"os"
"smg/cmd"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
AppName = "smg"
RootCmd = &cobra.Command{Use: AppName}
cfgFile string
)
type Header struct {
key string
value string
}
func main() {
defer func() {
if err := recover(); err != nil {
log.Println("by bie. try -h for help.")
}
}()
RootCmd.AddCommand(cmd.InitServer())
RootCmd.AddCommand(cmd.DbDumper())
RootCmd.AddCommand(cmd.Decrypt())
RootCmd.AddCommand(cmd.Encrypt())
RootCmd.AddCommand(cmd.Gen())
RootCmd.AddCommand(cmd.GenKey())
RootCmd.AddCommand(cmd.Verify())
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 {
home, err := os.UserHomeDir()
cobra.CheckErr(err)
viper.AddConfigPath(home)
viper.SetConfigType("yaml")
viper.SetConfigName(".EDH")
}
viper.AutomaticEnv() // read in environment variables that match
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
}
}