From a25b7530f219f9ad6fb9e8882783f998045a0e77 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 13 Mar 2021 23:39:35 +0100 Subject: [PATCH] Support arguments in commands Signed-off-by: Knut Ahlers --- action_script.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/action_script.go b/action_script.go index 70fa970..b29b360 100644 --- a/action_script.go +++ b/action_script.go @@ -17,6 +17,16 @@ func init() { return nil } + var command []string + for _, arg := range r.Command { + tmp, err := formatMessage(arg, m, ruleDef, nil) + if err != nil { + return errors.Wrap(err, "execute command argument template") + } + + command = append(command, tmp) + } + ctx, cancel := context.WithTimeout(context.Background(), cfg.CommandTimeout) defer cancel() @@ -35,7 +45,7 @@ func init() { return errors.Wrap(err, "encoding script input") } - cmd := exec.CommandContext(ctx, r.Command[0], r.Command[1:]...) + cmd := exec.CommandContext(ctx, command[0], command[1:]...) cmd.Env = os.Environ() cmd.Stderr = os.Stderr cmd.Stdin = stdin