-
Notifications
You must be signed in to change notification settings - Fork 5
/
call.go
87 lines (78 loc) · 1.76 KB
/
call.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 main
import (
"context"
"regexp"
"strings"
"github.com/extism/cli"
"github.com/extism/go-sdk"
"github.com/spf13/cobra"
)
type devCallArgs struct {
devArgs
category string
repo string
parallel int
timeout int
}
func runDevCall(cmd *cobra.Command, args *devCallArgs) error {
plugin := args.args[0]
function := args.args[1]
data, err := args.loadDataFile()
if err != nil {
return err
}
rx := ®exp.Regexp{}
if args.repo != "" {
rx = regexp.MustCompile(args.repo)
}
wasm := []extism.Wasm{}
if strings.HasPrefix(plugin, "http://") || strings.HasPrefix(plugin, "https://") {
wasm = append(wasm, extism.WasmUrl{Url: plugin})
} else {
wasm = append(wasm, extism.WasmFile{Path: plugin})
}
pool := NewPool(args.parallel)
printed := false
for _, r := range data.Repos {
RunTask(pool, func(repo repo) {
if args.category != "" && repo.Category != args.category {
return
}
if args.repo != "" {
if !rx.MatchString(repo.Url) {
return
}
}
p := repo.path()
cli.Log("Running plugin", plugin, "in", p)
if args.parallel <= 1 {
if !printed {
cli.Print()
printed = true
}
cli.Print(p)
}
ctx := context.Background()
config := extism.PluginConfig{}
manifest := extism.Manifest{
Wasm: wasm,
AllowedPaths: map[string]string{p: "/"},
}
if args.timeout != 0 {
manifest.Timeout = uint64(args.timeout)
}
plug, err := extism.NewPlugin(ctx, manifest, config, []extism.HostFunction{})
if err != nil {
cli.Print("Unable to create plugin:", err)
return
}
_, output, err := plug.Call(function, []byte(repo.Url))
if err != nil {
cli.Print("Plugin call failed in", p+":", err)
}
cli.Print(string(output))
}, r)
}
pool.Wait()
return nil
}