package config import ( "fmt" "strings" ) // 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) } if strings.TrimSpace(path) == "" { return "", fmt.Errorf("reference catalog %s %q has an empty source path", kind, id) } return path, nil }