diff --git a/pkg/types/member.go b/pkg/types/member.go index 4463f4dc..e3558060 100644 --- a/pkg/types/member.go +++ b/pkg/types/member.go @@ -23,7 +23,7 @@ type MemberProfile struct { CanSeeInactiveCursors bool `json:"can_see_inactive_cursors" mapstructure:"can_see_inactive_cursors"` // plugin scope - Plugins map[string]any `json:"plugins"` + Plugins PluginSettings `json:"plugins"` } type MemberProvider interface { diff --git a/pkg/types/plugins.go b/pkg/types/plugins.go index fa57b8f1..d0abd674 100644 --- a/pkg/types/plugins.go +++ b/pkg/types/plugins.go @@ -2,10 +2,16 @@ package types import ( "errors" + "fmt" + "github.com/demodesk/neko/pkg/utils" "github.com/spf13/cobra" ) +var ( + ErrPluginSettingsNotFound = errors.New("plugin settings not found") +) + type Plugin interface { Name() string Config() PluginConfig @@ -61,3 +67,15 @@ func (p *PluginManagers) Validate() error { return nil } + +type PluginSettings map[string]any + +func (p PluginSettings) Unmarshal(name string, def any) error { + if p == nil { + return fmt.Errorf("%w: %s", ErrPluginSettingsNotFound, name) + } + if _, ok := p[name]; !ok { + return fmt.Errorf("%w: %s", ErrPluginSettingsNotFound, name) + } + return utils.Decode(p[name], def) +} diff --git a/pkg/types/session.go b/pkg/types/session.go index 1b4d1f7f..4ec4085c 100644 --- a/pkg/types/session.go +++ b/pkg/types/session.go @@ -49,7 +49,7 @@ type Settings struct { MercifulReconnect bool `json:"merciful_reconnect"` // plugin scope - Plugins map[string]any `json:"plugins"` + Plugins PluginSettings `json:"plugins"` } type Session interface {