use propper logger

This commit is contained in:
2026-01-09 17:44:45 +01:00
parent 42a1080981
commit d3c277eb7f
5 changed files with 52 additions and 28 deletions

View File

@@ -1,7 +1,7 @@
package oplcli
import (
"fmt"
"log/slog"
"os"
)
@@ -12,67 +12,67 @@ type Config struct {
func Scan(files []string, config Config) {
gameList, err := loadGamelist(config.GameListLocation)
if err != nil {
fmt.Printf("Failed to load game list: %v", err)
slog.Error("Failed to load game list", "file", config.GameListLocation)
os.Exit(1)
}
for _, file := range files {
fmt.Printf("Scanning file: %s\n", file)
slog.Info("Scanning file", "file", file)
gameID, err := scanGameFileForID(file)
if err != nil {
fmt.Printf("Failed to scan game file: %s", err)
slog.Error("Failed to scan game file", "file", file)
os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
slog.Info("Found game ID", "id", gameID)
gameName := gameList[gameID]
fmt.Printf("Found game name: %s\n", gameName)
slog.Info("Found game name", "name", gameName)
}
}
func Rename(files []string, config Config) {
gameList, err := loadGamelist(config.GameListLocation)
if err != nil {
fmt.Printf("Failed to load game list: %v", err)
slog.Error("Failed to load game list", "file", config.GameListLocation)
os.Exit(1)
}
for _, file := range files {
fmt.Printf("Scanning file: %s\n", file)
slog.Info("Scanning file", "file", file)
gameID, err := scanGameFileForID(file)
if err != nil {
fmt.Printf("Failed to scan game file: %s", err)
slog.Error("Failed to scan game file", "file", file)
os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
slog.Info("Found game ID", "id", gameID)
gameName := gameList[gameID]
fmt.Printf("Found game name: %s\n", gameName)
slog.Info("Found game name", "name", gameName)
newPath, err := renameGameFile(file, gameName)
if err != nil {
fmt.Printf("Failed to rename file: %v", err)
slog.Error("Failed to reanme file", "file", file, "gameName", gameName, "err", err)
os.Exit(1)
}
fmt.Printf("Renamed %s to %s", file, newPath)
slog.Info("Renamed file", "file", file, "to", newPath)
}
}
func DownloadGameArt(files []string, output string, config Config) {
for _, file := range files {
fmt.Printf("Scanning file: %s\n", file)
slog.Info("Scanning file", "file", file)
gameID, err := scanGameFileForID(file)
if err != nil {
fmt.Printf("Failed to scan game file: %s", err)
slog.Error("Failed to scan game file", "file", file)
os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
slog.Info("Found game ID", "id", gameID)
downloadArtForGame(gameID, output)
}
@@ -80,15 +80,15 @@ func DownloadGameArt(files []string, output string, config Config) {
func DownloadCfg(files []string, output string, mode FileMode, config Config) {
for _, file := range files {
fmt.Printf("Scanning file: %s\n", file)
slog.Info("Scanning file", "file", file)
gameID, err := scanGameFileForID(file)
if err != nil {
fmt.Printf("Failed to scan game file: %s", err)
slog.Error("Failed to scan game file", "file", file)
os.Exit(1)
}
fmt.Printf("Found game ID: %s\n", gameID)
slog.Info("Found game ID", "id", gameID)
downloadCfgForGame(gameID, output, mode)
}