-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplugin.go
54 lines (46 loc) · 1.25 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Package yamldiscovery implements a launchr plugin to
// discover actions defined in yaml.
package yamldiscovery
import (
"context"
"math"
"github.com/launchrctl/launchr/internal/launchr"
"github.com/launchrctl/launchr/pkg/action"
)
func init() {
launchr.RegisterPlugin(&Plugin{})
}
// Plugin is a [launchr.Plugin] to discover actions defined in yaml.
type Plugin struct {
am action.Manager
app launchr.App
}
// PluginInfo implements [launchr.Plugin] interface.
func (p *Plugin) PluginInfo() launchr.PluginInfo {
return launchr.PluginInfo{
Weight: math.MinInt,
}
}
// OnAppInit implements [launchr.Plugin] interface to provide discovered actions.
func (p *Plugin) OnAppInit(app launchr.App) error {
app.GetService(&p.am)
p.app = app
return nil
}
// DiscoverActions implements [action.DiscoveryPlugin] interface.
func (p *Plugin) DiscoverActions(ctx context.Context) ([]*action.Action, error) {
var res []*action.Action
idp := p.am.GetActionIDProvider()
for _, fs := range p.app.GetRegisteredFS() {
if fs, ok := fs.(action.DiscoveryFS); ok {
d := action.NewYamlDiscovery(fs)
d.SetActionIDProvider(idp)
discovered, err := d.Discover(ctx)
if err != nil {
return nil, err
}
res = append(res, discovered...)
}
}
return res, nil
}