-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
56 lines (47 loc) · 1.07 KB
/
main.go
File metadata and controls
56 lines (47 loc) · 1.07 KB
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
package main
import (
_ "embed"
"log"
"os"
"dback/internal/debug"
"dback/ui"
)
//go:embed logo.png
var logoBytes []byte
// appVersion is set at build time via -ldflags; defaults to "3.2.0" for local runs.
var appVersion = "3.2.0"
func main() {
args := os.Args[1:]
if debugEnabledFromArgs(args) || debug.EnabledFromEnv() {
debug.Enable()
log.SetOutput(os.Stderr)
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
log.Println("dback debug mode enabled (stderr activity logging)")
}
os.Args = append([]string{os.Args[0]}, stripDebugFlag(args)...)
defer func() {
if r := recover(); r != nil {
log.Printf("panic: %v\n%s", r, debug.Stack())
panic(r)
}
}()
ui.New(logoBytes, appVersion).Run()
}
func debugEnabledFromArgs(args []string) bool {
for _, arg := range args {
if arg == "--debug" || arg == "-debug" {
return true
}
}
return false
}
func stripDebugFlag(args []string) []string {
out := make([]string, 0, len(args))
for _, arg := range args {
if arg == "--debug" || arg == "-debug" {
continue
}
out = append(out, arg)
}
return out
}