package cli import ( "fmt" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/hachem-wtf/benson/internal/config" "github.com/hachem-wtf/benson/internal/modrinth" ) type compatMod struct { slug string filename string } type checkResult struct { compatible []compatMod incompatible []string failed []string } func runCheck(m *model) tea.Cmd { m.busy = true cfg := m.cfg return tea.Batch(m.spin.Tick, func() tea.Msg { return outputMsg{text: checkReport(cfg)} }) } func checkReport(cfg *config.Config) string { client := modrinth.NewClient() var res checkResult for _, mod := range cfg.ModrinthMods { versions, err := client.GetVersions(mod.Slug) if err != nil { res.failed = append(res.failed, mod.Slug) continue } var match *modrinth.Version if mod.Pinned() { match = modrinth.FindVersion(versions, mod.Version) } else { match = modrinth.CompatibleVersion(versions, cfg.MinecraftVersion, "fabric") } if match == nil { res.incompatible = append(res.incompatible, mod.Slug) continue } filename := match.VersionNumber if len(match.Files) > 0 { filename = match.Files[0].Filename } res.compatible = append(res.compatible, compatMod{slug: mod.Slug, filename: filename}) } return renderCheck(cfg, res) } func renderCheck(cfg *config.Config, res checkResult) string { rows := []string{ headingStyle.Render(fmt.Sprintf("Compatibility · MC %s · Fabric", cfg.MinecraftVersion)), "", } if len(res.compatible) > 0 { rows = append(rows, successStyle.Render("Compatible")) for _, c := range res.compatible { rows = append(rows, " "+successStyle.Render("✓ ")+c.slug+mutedStyle.Render(" → "+c.filename)) } rows = append(rows, "") } if len(res.incompatible) > 0 { rows = append(rows, errorStyle.Render("No compatible version")) for _, slug := range res.incompatible { rows = append(rows, " "+errorStyle.Render("✗ ")+slug) } rows = append(rows, "") } if len(res.failed) > 0 { rows = append(rows, warnStyle.Render("Failed to check")) for _, slug := range res.failed { rows = append(rows, " "+warnStyle.Render("! ")+slug) } rows = append(rows, "") } total := len(cfg.ModrinthMods) ok := len(res.compatible) rows = append(rows, mutedStyle.Render(fmt.Sprintf("Summary: %d/%d mods compatible", ok, total))) if len(res.incompatible) == 0 && len(res.failed) == 0 { rows = append(rows, successStyle.Render("Safe to generate.")) } else { rows = append(rows, warnStyle.Render("Not all mods are compatible — generate may have issues.")) } return lipgloss.JoinVertical(lipgloss.Left, rows...) }