Files
opl-cli/internal/gamelist.go
2026-01-09 17:44:45 +01:00

41 lines
669 B
Go

package oplcli
import (
"bufio"
"fmt"
"log/slog"
"os"
"strings"
)
func loadGamelist(filepath string) (map[string]string, error) {
file, err := os.Open(filepath)
if err != nil {
return nil, fmt.Errorf("Failed to open file: %w", err)
}
defer file.Close()
gameList := make(map[string]string)
lineNum := 0
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
lineNum++
substrings := strings.SplitN(line, " ", 2)
if len(substrings) != 2 {
slog.Warn("Line in gamelist is malformed", "line", lineNum)
continue
}
key := substrings[0]
value := substrings[1]
gameList[key] = value
}
return gameList, nil
}