-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin.go
87 lines (71 loc) · 1.95 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Package plasmactlbump implements a launchr plugin with bump functionality
package plasmactlbump
import (
"context"
_ "embed"
"github.com/launchrctl/keyring"
"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] plugin providing bump functionality.
type Plugin struct {
k keyring.Keyring
cfg launchr.Config
}
// PluginInfo implements [launchr.Plugin] interface.
func (p *Plugin) PluginInfo() launchr.PluginInfo {
return launchr.PluginInfo{
Weight: 10,
}
}
// OnAppInit implements [launchr.Plugin] interface.
func (p *Plugin) OnAppInit(app launchr.App) error {
app.GetService(&p.cfg)
app.GetService(&p.k)
return nil
}
// DiscoverActions implements [launchr.ActionDiscoveryPlugin] interface.
func (p *Plugin) DiscoverActions(_ context.Context) ([]*action.Action, error) {
a := action.NewFromYAML("bump", actionYaml)
a.SetRuntime(action.NewFnRuntime(func(_ context.Context, a *action.Action) error {
input := a.Input()
doSync := input.Opt("sync").(bool)
dryRun := input.Opt("dry-run").(bool)
allowOverride := input.Opt("allow-override").(bool)
vaultpass := input.Opt("vault-pass").(string)
last := input.Opt("last").(bool)
showProgress := false
if launchr.Log().Level() == 0 {
showProgress = true
}
if !doSync {
bumpAction := BumpAction{last: last, dryRun: dryRun}
return bumpAction.Execute()
}
if !doSync {
bumpAction := BumpAction{last: last, dryRun: dryRun}
return bumpAction.Execute()
}
syncAction := SyncAction{
keyring: p.k,
domainDir: ".",
buildDir: ".compose/build",
packagesDir: ".compose/packages",
dryRun: dryRun,
allowOverride: allowOverride,
vaultPass: vaultpass,
showProgress: showProgress,
}
err := syncAction.Execute()
if err != nil {
return err
}
return nil
}))
return []*action.Action{a}, nil
}