Centralize report name resolution
This commit is contained in:
86
internal/report/names.go
Normal file
86
internal/report/names.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package report
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
CommandNameDaily = "daily"
|
||||
CommandNameTomorrow = "tomorrow"
|
||||
CommandNameHourly = "hourly"
|
||||
CommandNameThreeDay = "three-day"
|
||||
CommandNameWeekend = "weekend"
|
||||
CommandNameStorm = "storm"
|
||||
|
||||
BatchNameMorning = "morning"
|
||||
BatchNameEvening = "evening"
|
||||
)
|
||||
|
||||
func IDForCommandName(name string) (ID, error) {
|
||||
switch name {
|
||||
case CommandNameDaily:
|
||||
return DailyToday, nil
|
||||
case CommandNameTomorrow:
|
||||
return Tomorrow, nil
|
||||
case CommandNameHourly:
|
||||
return Hourly, nil
|
||||
case CommandNameThreeDay:
|
||||
return ThreeDay, nil
|
||||
case CommandNameWeekend:
|
||||
return Weekend, nil
|
||||
case CommandNameStorm:
|
||||
return Storm, nil
|
||||
default:
|
||||
return "", fmt.Errorf("unknown report command %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
func CommandNames() []string {
|
||||
return []string{
|
||||
CommandNameDaily,
|
||||
CommandNameTomorrow,
|
||||
CommandNameHourly,
|
||||
CommandNameThreeDay,
|
||||
CommandNameWeekend,
|
||||
CommandNameStorm,
|
||||
}
|
||||
}
|
||||
|
||||
func IDForConfigKey(key string) (ID, error) {
|
||||
normalized := strings.ReplaceAll(strings.TrimSpace(strings.ToLower(key)), "-", "_")
|
||||
switch normalized {
|
||||
case "daily", "daily_today":
|
||||
return DailyToday, nil
|
||||
case "tomorrow":
|
||||
return Tomorrow, nil
|
||||
case "hourly":
|
||||
return Hourly, nil
|
||||
case "three_day", "three_day_outlook":
|
||||
return ThreeDay, nil
|
||||
case "weekend", "weekend_outlook":
|
||||
return Weekend, nil
|
||||
case "storm", "storm_report":
|
||||
return Storm, nil
|
||||
default:
|
||||
return "", fmt.Errorf("report config key %q is not a known report", key)
|
||||
}
|
||||
}
|
||||
|
||||
func BatchForCommandName(name string) (Batch, error) {
|
||||
switch name {
|
||||
case BatchNameMorning:
|
||||
return Morning, nil
|
||||
case BatchNameEvening:
|
||||
return Evening, nil
|
||||
default:
|
||||
return "", fmt.Errorf("unknown batch command %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
func BatchCommandNames() []string {
|
||||
return []string{
|
||||
BatchNameMorning,
|
||||
BatchNameEvening,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user