From 37b131c74cc8161f87654050e5683295edc122fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 16 Jun 2024 18:08:46 +0200 Subject: [PATCH] fix plugin settings unmarshal by changing to "name.key". --- pkg/types/plugins.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/types/plugins.go b/pkg/types/plugins.go index d0abd674..c0f271f8 100644 --- a/pkg/types/plugins.go +++ b/pkg/types/plugins.go @@ -3,6 +3,7 @@ package types import ( "errors" "fmt" + "strings" "github.com/demodesk/neko/pkg/utils" "github.com/spf13/cobra" @@ -74,8 +75,17 @@ func (p PluginSettings) Unmarshal(name string, def any) error { if p == nil { return fmt.Errorf("%w: %s", ErrPluginSettingsNotFound, name) } - if _, ok := p[name]; !ok { + // loop through the plugin settings and take only the one that starts with the name + // because the settings are stored in a map["plugin_name.setting_name"] = value + newMap := make(map[string]any) + for k, v := range p { + if strings.HasPrefix(k, name+".") { + newMap[strings.TrimPrefix(k, name+".")] = v + } + } + fmt.Printf("newMap: %+v\n", newMap) + if len(newMap) == 0 { return fmt.Errorf("%w: %s", ErrPluginSettingsNotFound, name) } - return utils.Decode(p[name], def) + return utils.Decode(newMap, def) }