Get plugin details if hook does not match signature

This commit is contained in:
Austin Roberts 2022-03-14 10:52:22 -05:00
parent adcf21f453
commit d3268003ac

View File

@ -18,8 +18,13 @@ import (
type Subcommand func(*cli.Context, []string) error type Subcommand func(*cli.Context, []string) error
type pluginDetails struct {
p *plugin.Plugin
name string
}
type PluginLoader struct { type PluginLoader struct {
Plugins []*plugin.Plugin Plugins []pluginDetails
Subcommands map[string]Subcommand Subcommands map[string]Subcommand
Flags []*flag.FlagSet Flags []*flag.FlagSet
LookupCache map[string][]interface{} LookupCache map[string][]interface{}
@ -31,9 +36,11 @@ func (pl *PluginLoader) Lookup(name string, validate func(interface{}) bool) []i
} }
results := []interface{}{} results := []interface{}{}
for _, plugin := range pl.Plugins { for _, plugin := range pl.Plugins {
if v, err := plugin.Lookup(name); err == nil { if v, err := plugin.p.Lookup(name); err == nil {
if validate(v) { if validate(v) {
results = append(results, v) results = append(results, v)
} else {
log.Warn("Plugin matches hook but not signature", "plugin", plugin.name, "hook", name)
} }
} }
} }
@ -53,7 +60,7 @@ var DefaultPluginLoader *PluginLoader
func NewPluginLoader(target string) (*PluginLoader, error) { func NewPluginLoader(target string) (*PluginLoader, error) {
pl := &PluginLoader{ pl := &PluginLoader{
Plugins: []*plugin.Plugin{}, Plugins: []pluginDetails{},
Subcommands: make(map[string]Subcommand), Subcommands: make(map[string]Subcommand),
Flags: []*flag.FlagSet{}, Flags: []*flag.FlagSet{},
LookupCache: make(map[string][]interface{}), LookupCache: make(map[string][]interface{}),
@ -98,7 +105,7 @@ func NewPluginLoader(target string) (*PluginLoader, error) {
} }
} }
} }
pl.Plugins = append(pl.Plugins, plug) pl.Plugins = append(pl.Plugins, pluginDetails{plug, fpath})
} }
return pl, nil return pl, nil
} }