buildScheduleOptions constructs the huh option list for the schedule frequency form. The default option (matching the current frequency) is placed first.
(rawExpr, currentFreq string)
| 284 | // buildScheduleOptions constructs the huh option list for the schedule frequency form. |
| 285 | // The default option (matching the current frequency) is placed first. |
| 286 | func buildScheduleOptions(rawExpr, currentFreq string) []huh.Option[string] { |
| 287 | options := make([]huh.Option[string], 0, len(standardScheduleFrequencies)+1) |
| 288 | |
| 289 | // If the current schedule doesn't match any standard frequency, add a "Custom" entry |
| 290 | if currentFreq == "custom" { |
| 291 | label := fmt.Sprintf("Custom: %s (keep existing)", rawExpr) |
| 292 | options = append(options, huh.NewOption(label, "custom")) |
| 293 | } |
| 294 | |
| 295 | // Standard frequency options — mark the one matching the current schedule |
| 296 | for _, f := range standardScheduleFrequencies { |
| 297 | label := f.Label |
| 298 | if f.Value == currentFreq { |
| 299 | label += " (current)" |
| 300 | } |
| 301 | options = append(options, huh.NewOption(label, f.Value)) |
| 302 | } |
| 303 | |
| 304 | // Move the default option to the front so huh selects it initially. |
| 305 | // classifyScheduleFrequency always returns a non-empty string ("custom" as its last resort), |
| 306 | // so currentFreq is never empty when this function is called from selectScheduleFrequency. |
| 307 | reordered := sliceutil.Filter(options, func(opt huh.Option[string]) bool { return opt.Value == currentFreq }) |
| 308 | rest := sliceutil.Filter(options, func(opt huh.Option[string]) bool { return opt.Value != currentFreq }) |
| 309 | return append(reordered, rest...) |
| 310 | } |