-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.go
42 lines (33 loc) · 1001 Bytes
/
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
// Package example implements an example launchr plugin
package example
import (
"context"
_ "embed"
"github.com/launchrctl/launchr"
"github.com/launchrctl/launchr/pkg/action"
)
//go:embed action.yaml
var actionYaml []byte
func init() {
launchr.RegisterPlugin(&Plugin{})
}
// Plugin is [launchr.Plugin] providing example action.
type Plugin struct{}
// PluginInfo implements [launchr.Plugin] interface.
func (p *Plugin) PluginInfo() launchr.PluginInfo {
return launchr.PluginInfo{}
}
// DiscoverActions implements [launchr.ActionDiscoveryPlugin] interface.
func (p *Plugin) DiscoverActions(_ context.Context) ([]*action.Action, error) {
a := action.NewFromYAML("example:plugin-runtime", actionYaml)
a.SetRuntime(action.NewFnRuntime(func(_ context.Context, _ *action.Action) error {
return example()
}))
return []*action.Action{a}, nil
}
func example() error {
// Code to execute by command goes here
launchr.Term().Println()
launchr.Term().Println("Hello world")
return nil
}