-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
55 lines (49 loc) · 1.08 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
package main
import (
"log"
"log/slog"
"os"
"wombatt/cmd"
"github.com/alecthomas/kong"
)
func logSetup(levelName string) {
var level slog.Level
switch levelName {
case "debug":
level = slog.LevelDebug
case "info":
level = slog.LevelInfo
case "warn":
level = slog.LevelWarn
case "error":
level = slog.LevelError
default:
log.Fatalf("invalid log level %q", levelName)
}
opts := &slog.HandlerOptions{
Level: level,
}
logger := slog.New(slog.NewTextHandler(os.Stderr, opts))
slog.SetDefault(logger)
}
func main() {
cli := cmd.CLI{
Globals: cmd.Globals{},
}
ctx := kong.Parse(&cli,
kong.Name("wombatt"),
kong.Description("A wanna-be Swiss army knife for inverter and battery monitoring."),
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
// Compact: true,
}),
kong.Vars{
"version": "0.0.8",
"bms_types": "EG4LLv2,lifepower4,pacemodbus",
"device_types": "serial,hidraw,tcp",
"protocols": "auto,ModbusRTU,ModbusTCP,lifepower4",
})
logSetup(cli.Globals.LogLevel)
err := ctx.Run(&cli.Globals)
ctx.FatalIfErrorf(err)
}