package cli import ( "strings" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/hachem-wtf/benson/internal/config" ) func defaultCommands() []command { return []command{ { name: "mods", desc: "Manage mods — list, search, add, pin versions, remove", run: runMods, }, { name: "start", desc: "Start the server in the background", run: runStart, }, { name: "stop", desc: "Stop the running server", run: runStop, }, { name: "restart", desc: "Restart the server", run: runRestart, }, { name: "status", desc: "Show whether the server is running, players, and version", run: runStatus, }, { name: "check", desc: "Check whether the configured mods are compatible", run: runCheck, }, { name: "generate", desc: "Download the server and mods and generate a server directory", run: runGenerate, }, { name: "merge", desc: "Back up the existing server and merge the generated files into it", run: runMerge, }, { name: "clean", desc: "Remove generated files and/or the latest backup (generated|latest|all)", run: runClean, }, { name: "help", desc: "Show available commands", run: func(m *model) tea.Cmd { return tea.Println(helpBlock(m.commands)) }, }, } } func welcomeBlock(cfg *config.Config, version string) string { header := lipgloss.JoinHorizontal( lipgloss.Bottom, titleStyle.Render("BENSON"), subtitleStyle.Render(" v"+version), ) inner := lipgloss.JoinVertical( lipgloss.Left, header, mutedStyle.Render("Fabric · MC "+cfg.MinecraftVersion), ) hint := mutedStyle.Render("Tab autocompletes · Ctrl+C quits") return lipgloss.JoinVertical(lipgloss.Left, bannerStyle.Render(inner), "", hint) } func helpBlock(cmds []command) string { rows := []string{headingStyle.Render("Commands"), ""} for _, c := range cmds { rows = append(rows, " "+bulletStyle.Render(padRight(c.name, 14))+mutedStyle.Render(c.desc)) } rows = append(rows, " "+bulletStyle.Render(padRight("exit", 14))+mutedStyle.Render("Exit Benson")) return lipgloss.JoinVertical(lipgloss.Left, rows...) } func padRight(s string, n int) string { if pad := n - len([]rune(s)); pad > 0 { return s + strings.Repeat(" ", pad) } return s }