2026-11-27 16:12:16 +00:00
|
|
|
package config
|
|
|
|
|
|
2026-11-27 21:16:27 +00:00
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
2026-11-27 16:12:16 +00:00
|
|
|
|
|
|
|
|
// SelectSetting returns the source for a selected setting, or no source for an omitted selection.
|
|
|
|
|
func (catalog ReferenceCatalogConfig) SelectSetting(id string) (string, error) {
|
|
|
|
|
return selectReference("setting", id, catalog.Settings)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SelectSystem returns the source for a selected system, or no source for an omitted selection.
|
|
|
|
|
func (catalog ReferenceCatalogConfig) SelectSystem(id string) (string, error) {
|
|
|
|
|
return selectReference("system", id, catalog.Systems)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func selectReference(kind, id string, entries map[string]string) (string, error) {
|
|
|
|
|
if id == "" {
|
|
|
|
|
return "", nil
|
|
|
|
|
}
|
|
|
|
|
path, ok := entries[id]
|
|
|
|
|
if !ok {
|
|
|
|
|
return "", fmt.Errorf("unknown reference catalog %s %q", kind, id)
|
|
|
|
|
}
|
2026-11-27 21:16:27 +00:00
|
|
|
if strings.TrimSpace(path) == "" {
|
|
|
|
|
return "", fmt.Errorf("reference catalog %s %q has an empty source path", kind, id)
|
|
|
|
|
}
|
2026-11-27 16:12:16 +00:00
|
|
|
return path, nil
|
|
|
|
|
}
|