summaryrefslogtreecommitdiff
path: root/plugins.go
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2022-02-21 22:41:32 -0500
committerDave Henderson <dhenderson@gmail.com>2022-02-27 20:16:18 -0500
commit610a8b5a408cb3d08f4e4e2d6cf9cbe7194490d5 (patch)
tree5a79319666ca7d71ee6744fcfd59dec07b0c3347 /plugins.go
parent2aa13dd3cf08ee24eb174edb78ee4d13415005b5 (diff)
Support piping input to plugin
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'plugins.go')
-rw-r--r--plugins.go23
1 files changed, 20 insertions, 3 deletions
diff --git a/plugins.go b/plugins.go
index 89309c0e..3e6e1f04 100644
--- a/plugins.go
+++ b/plugins.go
@@ -19,11 +19,17 @@ import (
func bindPlugins(ctx context.Context, cfg *config.Config, funcMap template.FuncMap) error {
for k, v := range cfg.Plugins {
+ timeout := cfg.PluginTimeout
+ if v.Timeout != 0 {
+ timeout = v.Timeout
+ }
+
plugin := &plugin{
ctx: ctx,
name: k,
- path: v,
- timeout: cfg.PluginTimeout,
+ path: v.Cmd,
+ timeout: timeout,
+ pipe: v.Pipe,
stderr: cfg.Stderr,
}
if _, ok := funcMap[plugin.name]; ok {
@@ -40,6 +46,7 @@ type plugin struct {
stderr io.Writer
name, path string
timeout time.Duration
+ pipe bool
}
// builds a command that's appropriate for running scripts
@@ -79,8 +86,18 @@ func (p *plugin) run(args ...interface{}) (interface{}, error) {
ctx, cancel := context.WithTimeout(p.ctx, p.timeout)
defer cancel()
+
+ var stdin *bytes.Buffer
+ if p.pipe && len(a) > 0 {
+ stdin = bytes.NewBufferString(a[len(a)-1])
+ a = a[:len(a)-1]
+ }
+
c := exec.CommandContext(ctx, name, a...)
- c.Stdin = nil
+ if stdin != nil {
+ c.Stdin = stdin
+ }
+
c.Stderr = p.stderr
outBuf := &bytes.Buffer{}
c.Stdout = outBuf