kleinCommand/main.go

62 lines
1.2 KiB
Go
Raw Normal View History

package main
import (
2025-07-19 20:58:05 +02:00
"context"
2025-07-19 22:05:15 +02:00
"github.com/DariusKlein/kleinCommand/commands/config"
2025-07-19 20:58:05 +02:00
"github.com/DariusKlein/kleinCommand/commands/templateCommand"
"github.com/DariusKlein/kleinCommand/common"
"github.com/urfave/cli/v3"
"log"
2025-07-19 22:05:15 +02:00
"log/slog"
2025-07-19 20:58:05 +02:00
"net/mail"
"os"
2025-07-19 22:05:15 +02:00
"strings"
)
func main() {
2025-07-19 22:05:15 +02:00
conf, err := common.ReadConfig()
if err != nil {
log.Fatal(err)
}
setLogLevel(conf)
2025-07-19 20:58:05 +02:00
app := &cli.Command{
2024-05-24 19:41:44 +02:00
Name: "KleinCommand",
2025-07-19 20:58:05 +02:00
Usage: "CLI tool for internal use",
2024-05-24 19:41:44 +02:00
UsageText: "kleinCommand [category] [command] [arguments...]",
2025-07-19 20:58:05 +02:00
Version: "v0.1.0",
2024-05-24 19:41:44 +02:00
HideVersion: true,
2025-07-19 20:58:05 +02:00
Authors: []any{
mail.Address{
Name: "Darius",
Address: "darius.klein@dariusklein.nl",
2024-05-24 12:21:21 +02:00
},
},
DefaultCommand: "help",
Commands: []*cli.Command{
2025-07-19 20:58:05 +02:00
config.Category(),
templateCommand.Category(),
},
}
2025-07-19 20:58:05 +02:00
if err := app.Run(context.Background(), os.Args); err != nil {
log.Fatal(err)
}
}
2025-07-19 22:05:15 +02:00
func setLogLevel(conf common.Config) {
opts := &slog.HandlerOptions{}
switch strings.ToUpper(conf.Settings.LogLevel) {
case "INFO":
opts.Level = slog.LevelInfo
case "WARN":
opts.Level = slog.LevelWarn
case "DEBUG":
opts.Level = slog.LevelDebug
case "ERROR":
opts.Level = slog.LevelError
}
slog.SetLogLoggerLevel(opts.Level.Level())
}