/
main.go
99 lines (75 loc) · 1.86 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"flag"
"github.com/blang/semver"
"github.com/spf13/viper"
)
var (
progVersion = semver.Version{
Major: 1,
Minor: 1,
Patch: 0,
Pre: []semver.PRVersion{
{VersionStr: "beta"},
{VersionNum: 1, IsNum: true},
},
}
buildVersion string
)
func init() {
if buildVersion != "" {
progVersion.Build = []string{
buildVersion,
}
}
}
func main() {
// Initialize viper and default options.
InitConfig()
// Setup flags.
flag.String("config", viper.GetString("config"), "Alternate path to the config file.")
flag.Bool("debug", viper.GetBool("debug"), "Turn on debug output.")
flag.String("mongo.uri", viper.GetString("mongo.uri"), "URI of the MongoDB host or cluster.")
flag.String("smtp.host", viper.GetString("smtp.host"), "Host of the SMTP server.")
flag.Int("smtp.port", viper.GetInt("smtp.port"), "Port of the SMTP server.")
flag.String("smtp.user", viper.GetString("smtp.user"), "SMTP user.")
flag.String("smtp.password", viper.GetString("smtp.password"), "SMTP password.")
flag.String("smtp.from", viper.GetString("smtp.from"), "SMTP From address.")
flag.Parse()
// Visit all of the seen flags to update the config.
// All flag types in flag package support the getter interface.
flag.Visit(func(f *flag.Flag) {
viper.Set(f.Name, f.Value.(flag.Getter).Get())
})
args := flag.Args()
if len(args) == 0 {
PrintUsage("help")
}
// Route command.
switch args[0] {
case "version":
versionCmd(args[1:])
case "put":
putCmd(args[1:])
case "get":
getCmd(args[1:])
case "keys":
keysCmd(args[1:])
case "log":
logCmd(args[1:])
case "http":
httpCmd(args[1:])
case "config":
configCmd(args[1:])
case "subscribe":
subscribeCmd(args[1:])
case "unsubscribe":
unsubscribeCmd(args[1:])
default:
// Print usage of speific command.
if len(args) == 2 {
PrintUsage(args[1])
}
PrintUsage("help")
}
}