forked from omriharel/deej
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (52 loc) · 1.39 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
package main
import (
"flag"
"fmt"
"github.com/omriharel/deej"
)
var (
gitCommit string
versionTag string
buildType string
verbose bool
)
func init() {
flag.BoolVar(&verbose, "verbose", false, "show verbose logs (useful for debugging serial)")
flag.BoolVar(&verbose, "v", false, "shorthand for --verbose")
flag.Parse()
}
func main() {
// first we need a logger
logger, err := deej.NewLogger(buildType)
if err != nil {
panic(fmt.Sprintf("Failed to create logger: %v", err))
}
named := logger.Named("main")
named.Debug("Created logger")
named.Infow("Version info",
"gitCommit", gitCommit,
"versionTag", versionTag,
"buildType", buildType)
// provide a fair warning if the user's running in verbose mode
if verbose {
named.Debug("Verbose flag provided, all log messages will be shown")
}
// create the deej instance
d, err := deej.NewDeej(logger, verbose)
if err != nil {
named.Fatalw("Failed to create deej object", "error", err)
}
// if injected by build process, set version info to show up in the tray
if buildType != "" && (versionTag != "" || gitCommit != "") {
identifier := gitCommit
if versionTag != "" {
identifier = versionTag
}
versionString := fmt.Sprintf("Version %s-%s", buildType, identifier)
d.SetVersion(versionString)
}
// onwards, to glory
if err = d.Initialize(); err != nil {
named.Fatalw("Failed to initialize deej", "error", err)
}
}