hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/internal/setup/setup.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/setup/setup.go')
-rw-r--r--internal/setup/setup.go69
1 files changed, 31 insertions, 38 deletions
diff --git a/internal/setup/setup.go b/internal/setup/setup.go
index c2f8c10..c3c957c 100644
--- a/internal/setup/setup.go
+++ b/internal/setup/setup.go
@@ -27,46 +27,49 @@ func Run() error {
backupLoc = cfg.BackupLocation
preCmd = cfg.MergePreCommand
postCmd = cfg.MergePostCommand
- modsText = strings.Join(cfg.ModrinthMods, "\n")
- confirm = true
)
games, loaders, installers := fetchFabricVersions()
form := huh.NewForm(
huh.NewGroup(
- huh.NewNote().
- Title("Benson setup").
- Description("Configure the server manager.\nThe Discord bot is optional — run `benson setup bot` for that."),
- ),
- huh.NewGroup(
- versionField("Minecraft version", "The Minecraft release your server runs — newest stable is recommended", games, &mcVersion, "1.21.10"),
+ versionField("Minecraft version", "Which release your server runs · newest recommended", games, &mcVersion, "1.21.10"),
),
huh.NewGroup(
- versionField("Fabric loader version", "The Fabric mod loader that boots your mods — newest is recommended", loaders, &fabricLoader, "0.17.3"),
+ versionField("Fabric loader version", "The mod loader that boots your mods · newest recommended", loaders, &fabricLoader, "0.17.3"),
),
huh.NewGroup(
- versionField("Fabric installer version", "Builds the server jar from the loader — newest is recommended", installers, &loaderMeta, "1.1.0"),
+ versionField("Fabric installer version", "Builds the server jar · newest recommended", installers, &loaderMeta, "1.1.0"),
),
huh.NewGroup(
- huh.NewInput().Title("Java path").Description("Leave blank to use 'java' from PATH").Value(&javaPath),
- huh.NewInput().Title("Server location").Description("Live server directory, merged into by 'merge'").Value(&serverLoc),
- huh.NewInput().Title("Backup location").Description("Where server backups are written").Value(&backupLoc),
- huh.NewInput().Title("Pre-merge command").Description("Optional shell command run before merging").Value(&preCmd),
- huh.NewInput().Title("Post-merge command").Description("Optional shell command run after merging").Value(&postCmd),
- ).Title("Paths & hooks (optional)"),
+ huh.NewInput().Title("Java path").Description("Blank = use 'java' from PATH").Value(&javaPath),
+ huh.NewInput().Title("Server location").Description("Live server dir, merged into by 'merge'").Value(&serverLoc),
+ huh.NewInput().Title("Backup location").Description("Where backups are written").Value(&backupLoc),
+ ).Title("Locations (optional)"),
huh.NewGroup(
- huh.NewText().Title("Modrinth mods").Description("One mod slug per line").Lines(8).Value(&modsText),
- ).Title("Mods"),
- huh.NewGroup(
- huh.NewConfirm().Title("Write config/config.json?").Affirmative("Write").Negative("Cancel").Value(&confirm),
- ),
+ huh.NewInput().Title("Pre-merge command").Description("Optional shell command before merging").Value(&preCmd),
+ huh.NewInput().Title("Post-merge command").Description("Optional shell command after merging").Value(&postCmd),
+ ).Title("Merge hooks (optional)"),
)
if done, err := runForm(form); err != nil || !done {
return err
}
+ mods := pickMods(cfg.ModrinthMods, strings.TrimSpace(mcVersion), "fabric")
+
+ confirm := true
+ confirmForm := huh.NewForm(huh.NewGroup(
+ huh.NewConfirm().Title("Write config/config.json?").Affirmative("Write").Negative("Cancel").Value(&confirm),
+ ))
+ if done, err := runForm(confirmForm); err != nil || !done {
+ return err
+ }
+ if !confirm {
+ fmt.Println("Setup cancelled — nothing written.")
+ return nil
+ }
+
cfg.MinecraftVersion = strings.TrimSpace(mcVersion)
cfg.FabricLoaderVersion = strings.TrimSpace(fabricLoader)
cfg.LoaderMetaVersion = strings.TrimSpace(loaderMeta)
@@ -75,7 +78,7 @@ func Run() error {
cfg.BackupLocation = strings.TrimSpace(backupLoc)
cfg.MergePreCommand = strings.TrimSpace(preCmd)
cfg.MergePostCommand = strings.TrimSpace(postCmd)
- cfg.ModrinthMods = parseMods(modsText)
+ cfg.ModrinthMods = mods
if err := writeConfigFile(cfg); err != nil {
return err
@@ -106,14 +109,10 @@ func RunBot() error {
huh.NewGroup(
huh.NewNote().
Title("Benson bot setup").
- Description("Configure the Discord bot that posts Modrinth compatibility reports."),
- ),
- huh.NewGroup(
+ Description("Posts Modrinth compatibility reports to a Discord channel."),
huh.NewInput().Title("Discord bot token").Description("Developer Portal → Bot → Reset/Copy Token").Password(true).Value(&token).Validate(required("token")),
huh.NewInput().Title("Channel ID").Description("Channel where reports are posted").Value(&channelID).Validate(required("channel ID")),
huh.NewInput().Title("Check interval (minutes)").Value(&intervalStr).Validate(positiveInt),
- ).Title("Discord"),
- huh.NewGroup(
huh.NewConfirm().Title("Write config/config.json and config/api.json?").Affirmative("Write").Negative("Cancel").Value(&confirm),
),
)
@@ -176,10 +175,14 @@ func versionField(title, desc string, options []string, value *string, placehold
Title(title).
Description(desc).
Options(recommendedOptions(options)...).
- Height(12).
+ Height(selectHeight(len(options))).
Value(value)
}
+func selectHeight(n int) int {
+ return min(10, n) + 2
+}
+
func recommendedOptions(versions []string) []huh.Option[string] {
options := make([]huh.Option[string], len(versions))
for i, v := range versions {
@@ -243,16 +246,6 @@ func positiveInt(s string) error {
return nil
}
-func parseMods(text string) []string {
- mods := []string{}
- for _, line := range strings.Split(text, "\n") {
- if slug := strings.TrimSpace(line); slug != "" {
- mods = append(mods, slug)
- }
- }
- return mods
-}
-
func check() string {
return lipgloss.NewStyle().Foreground(lipgloss.Color("#22C55E")).Render("✓")
}