36 lines
1.3 KiB
Go
36 lines
1.3 KiB
Go
package setup
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"charm.land/huh/v2"
|
|
"git.zb-server.de/Sebi/ssh-netbox-wrapper/internal/config"
|
|
)
|
|
|
|
func editOperations(cfg *config.Config) error {
|
|
history, days, entries := strconv.Itoa(cfg.TUI.HistoryLimit), strconv.Itoa(cfg.Activity.RetentionDays), strconv.Itoa(cfg.Activity.MaxEntries)
|
|
enabled := cfg.Activity.Enabled
|
|
valid := func(s string) error {
|
|
n, err := strconv.Atoi(s)
|
|
if err != nil || n < 0 {
|
|
return fmt.Errorf("enter a non-negative number")
|
|
}
|
|
return nil
|
|
}
|
|
err := huh.NewForm(huh.NewGroup(
|
|
huh.NewInput().Title("Recent hosts shown").Description("10 by default; 0 shows all. Favorites are additional.").Value(&history).Validate(valid),
|
|
huh.NewConfirm().Title("Record local action history?").Description("Stores host, command name, duration and exit code; no arguments or output.").Value(&enabled),
|
|
huh.NewInput().Title("Retention in days").Description("0 = no age limit").Value(&days).Validate(valid),
|
|
huh.NewInput().Title("Maximum recorded actions").Description("0 = no count limit").Value(&entries).Validate(valid),
|
|
).Title("History & activity")).Run()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cfg.TUI.HistoryLimit, _ = strconv.Atoi(history)
|
|
cfg.Activity.RetentionDays, _ = strconv.Atoi(days)
|
|
cfg.Activity.MaxEntries, _ = strconv.Atoi(entries)
|
|
cfg.Activity.Enabled = enabled
|
|
return nil
|
|
}
|