-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (55 loc) · 1.33 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
package internal
import (
"fmt"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
var (
confPath string
keyPath string
verbose bool
useEmu bool
lgr *zap.Logger
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "firemage",
Short: shortDesc,
Long: longDesc,
}
func init() {
rootCmd.Flags().StringVarP(&keyPath, "key", "k", "service-account.json", descKey)
rootCmd.Flags().StringVarP(&confPath, "conf", "c", "conf.yaml", descConf)
rootCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, descDebug)
rootCmd.Flags().BoolVarP(&useEmu, "emulator", "e", false, descEmul)
}
func Main() {
must("execute command", rootCmd.Execute())
if logSync := initLogger(); logSync != nil {
defer logSync()
}
fb = NewFirebase()
fe = createGUI()
fe.run()
cancelF()
}
func initLogger() func() {
cfg := zap.NewDevelopmentConfig()
cfg.OutputPaths = []string{"log.txt"}
if !verbose {
cfg.Level = zap.NewAtomicLevelAt(zap.ErrorLevel)
}
var err error
lgr, err = cfg.Build()
must("build logger", err)
zap.ReplaceGlobals(lgr)
return func() {
must("log sync", lgr.Sync())
}
}
// must panics if the given error is not nil, with the given description. For initializations only.
func must(descr string, err error) {
if err != nil {
panic(fmt.Errorf("%s: %w", descr, err))
}
}