This repository has been archived by the owner on Feb 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
main.go
93 lines (84 loc) · 1.74 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
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"path"
"syscall"
"github.com/SoMuchForSubtlety/f1viewer/v2/internal/config"
"github.com/SoMuchForSubtlety/f1viewer/v2/internal/ui"
"github.com/SoMuchForSubtlety/f1viewer/v2/internal/util"
)
var (
version = "dev"
commit = ""
date = ""
)
func main() {
var showVersion bool
var openConfig bool
var openLogs bool
flag.BoolVar(&showVersion, "v", showVersion, "show version information")
flag.BoolVar(&showVersion, "version", showVersion, "show version information")
flag.BoolVar(&openConfig, "config", openConfig, "open config file")
flag.BoolVar(&openLogs, "logs", openLogs, "open logs directory")
flag.Parse()
if showVersion {
fmt.Println(buildVersion())
return
}
cfg, err := config.LoadConfig()
if err != nil {
fmt.Printf("Could not open config: %v\n", err)
os.Exit(1)
}
if openConfig {
cfgPath, err := config.GetConfigPath()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = util.Open(path.Join(cfgPath, "config.toml"))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return
}
if openLogs {
logPath, err := config.GetLogPath()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = util.Open(logPath)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return
}
ui := ui.NewUI(cfg, version)
go func() {
if err := ui.Run(); err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(0)
}()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
ui.Stop()
}
func buildVersion() string {
result := fmt.Sprintf("Version: %s", version)
if commit != "" {
result += fmt.Sprintf("\nGit commit: %s", commit)
}
if date != "" {
result += fmt.Sprintf("\nBuilt: %s", date)
}
return result
}