-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.go
More file actions
141 lines (117 loc) · 3.6 KB
/
Copy pathplugin.go
File metadata and controls
141 lines (117 loc) · 3.6 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Package plasmactlbump implements a launchr plugin with bump functionality
package plasmactlbump
import (
"context"
_ "embed"
"fmt"
"os"
"github.com/launchrctl/keyring"
"github.com/launchrctl/launchr"
"github.com/launchrctl/launchr/pkg/action"
)
//go:embed action.bump.yaml
var actionBumpYaml []byte
//go:embed action.dependencies.yaml
var actionDependenciesYaml []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.Services().Get(&p.cfg)
app.Services().Get(&p.k)
return nil
}
// DiscoverActions implements [launchr.ActionDiscoveryPlugin] interface.
func (p *Plugin) DiscoverActions(_ context.Context) ([]*action.Action, error) {
ba := action.NewFromYAML("bump", actionBumpYaml)
ba.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)
filterByResourceUsage := input.Opt("playbook-filter").(bool)
timeDepth := input.Opt("time-depth").(string)
vaultpass := input.Opt("vault-pass").(string)
last := input.Opt("last").(bool)
log, logLevel, streams, term := getLogger(a)
hideProgress := input.Opt("hide-progress").(bool)
if logLevel > 0 {
hideProgress = true
}
if !doSync {
bump := bumpAction{last: last, dryRun: dryRun}
bump.SetLogger(log)
bump.SetTerm(term)
return bump.Execute()
}
sync := syncAction{
keyring: p.k,
streams: streams,
domainDir: ".",
buildDir: ".compose/build",
packagesDir: ".compose/packages",
dryRun: dryRun,
filterByResourceUsage: filterByResourceUsage,
timeDepth: timeDepth,
allowOverride: allowOverride,
vaultPass: vaultpass,
showProgress: !hideProgress,
}
sync.SetLogger(log)
sync.SetTerm(term)
err := sync.Execute()
if err != nil {
return err
}
return nil
}))
da := action.NewFromYAML("dependencies", actionDependenciesYaml)
da.SetRuntime(action.NewFnRuntime(func(_ context.Context, a *action.Action) error {
log, _, _, term := getLogger(a)
input := a.Input()
source := input.Opt("source").(string)
if _, err := os.Stat(source); os.IsNotExist(err) {
term.Warning().Printfln("%s doesn't exist, fallback to current dir", source)
source = "."
} else {
term.Info().Printfln("Selected source is %s", source)
}
showPaths := input.Opt("mrn").(bool)
showTree := input.Opt("tree").(bool)
depth := int8(input.Opt("depth").(int)) //nolint:gosec
if depth == 0 {
return fmt.Errorf("depth value should not be zero")
}
target := input.Arg("target").(string)
dependencies := &dependenciesAction{}
dependencies.SetLogger(log)
dependencies.SetTerm(term)
return dependencies.run(target, source, !showPaths, showTree, depth)
}))
return []*action.Action{ba, da}, nil
}
func getLogger(a *action.Action) (*launchr.Logger, launchr.LogLevel, launchr.Streams, *launchr.Terminal) {
log := launchr.Log()
level := log.Level()
if rt, ok := a.Runtime().(action.RuntimeLoggerAware); ok {
log = rt.LogWith()
level = log.Level()
}
term := launchr.Term()
if rt, ok := a.Runtime().(action.RuntimeTermAware); ok {
term = rt.Term()
}
return log, level, a.Input().Streams(), term
}