diff options
| author | hachem <im@hachem.wtf> | 2026-08-29 03:29:51 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-29 03:29:51 +0200 |
| commit | a221b4c5edd3ff4d4a9d74113d9d3b8c7473133d (patch) | |
| tree | d902da32c84dad3d5fe0152be07d3bea6d4f9ee1 /internal/cli/check.go | |
| parent | f60177934a18daea3b24a37cf109bb2c7bfaaa72 (diff) | |
add: modrinth client and check command
Diffstat (limited to 'internal/cli/check.go')
| -rw-r--r-- | internal/cli/check.go | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/internal/cli/check.go b/internal/cli/check.go new file mode 100644 index 0000000..1df5137 --- /dev/null +++ b/internal/cli/check.go @@ -0,0 +1,100 @@ +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 _, slug := range cfg.ModrinthMods { + versions, err := client.GetVersions(slug) + if err != nil { + res.failed = append(res.failed, slug) + continue + } + + match := modrinth.CompatibleVersion(versions, cfg.MinecraftVersion, "fabric") + if match == nil { + res.incompatible = append(res.incompatible, slug) + continue + } + + filename := match.VersionNumber + if len(match.Files) > 0 { + filename = match.Files[0].Filename + } + res.compatible = append(res.compatible, compatMod{slug: 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...) +} |
