-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
65 lines (60 loc) · 1.38 KB
/
main.go
File metadata and controls
65 lines (60 loc) · 1.38 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
57
58
59
60
61
62
63
64
65
package main
import (
"context"
"github.com/DariusKlein/kleinCommand/commands/config"
"github.com/DariusKlein/kleinCommand/commands/service"
"github.com/DariusKlein/kleinCommand/commands/templateCommand"
"github.com/DariusKlein/kleinCommand/common"
"github.com/urfave/cli/v3"
"log"
"log/slog"
"net/mail"
"os"
"strings"
)
func main() {
conf, err := common.ReadConfig()
if err != nil {
slog.Error(err.Error())
} else {
setLogLevel(conf)
}
app := &cli.Command{
Name: "KleinCommand",
Usage: "CLI tool for internal use",
UsageText: "kleinCommand [category] [command] [arguments...]",
Version: "v0.1.0",
HideVersion: true,
Authors: []any{
mail.Address{
Name: "Darius",
Address: "darius.klein@dariusklein.nl",
},
},
DefaultCommand: "help",
Commands: []*cli.Command{
config.Category(),
templateCommand.Category(),
service.Category(),
},
}
if err := app.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
}
func setLogLevel(conf common.Config) {
var logLevel slog.Level
switch strings.ToUpper(conf.Settings.LogLevel) {
case "INFO":
logLevel = slog.LevelInfo
case "WARN":
logLevel = slog.LevelWarn
case "DEBUG":
logLevel = slog.LevelDebug
case "ERROR":
logLevel = slog.LevelError
default:
log.Fatal("unknown log level", logLevel, conf.Settings.LogLevel)
}
slog.SetLogLoggerLevel(logLevel)
}