-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_gui.go
70 lines (61 loc) · 1.34 KB
/
main_gui.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
//go:build !nogui
package main
import (
"flag"
"fmt"
"log/slog"
"os"
"github.com/ilius/ayandict/v2/pkg/appinfo"
"github.com/ilius/ayandict/v2/pkg/application"
"github.com/ilius/ayandict/v2/pkg/config"
"github.com/ilius/ayandict/v2/pkg/dictmgr"
"github.com/ilius/ayandict/v2/pkg/logging"
"github.com/ilius/ayandict/v2/pkg/server"
)
func runServerOnly(createConfig bool) {
conf, err := config.Load()
if err != nil {
panic(err)
}
if createConfig {
err := config.EnsureExists(conf)
if err != nil {
slog.Error("Failed creating config file", "err", err)
}
}
if !conf.WebEnable {
slog.Warn("Web is not enabled, set web_enable = true in " + config.Path())
}
dictmgr.InitDicts(conf)
server.StartServer(conf.LocalServerPorts[0])
}
func main() {
versionFlag := flag.Bool(
"version",
false,
"Show version and exit",
)
noGuiFlag := flag.Bool(
"no-gui",
false,
"Do not launch GUI",
)
createConfigFlag := flag.Bool(
"create-config",
false,
"With --no-gui: create config file (with defaults) if it does not exist",
)
flag.Parse()
if *versionFlag {
fmt.Printf("%v %v\n", appinfo.APP_DESC, appinfo.VERSION)
os.Exit(0)
}
// slog uses stdout
noColor := os.Getenv("NO_COLOLR") != ""
logging.SetupLogger(noColor, logging.DefaultLevel)
if *noGuiFlag {
runServerOnly(*createConfigFlag)
return
}
application.Run()
}