Skip to content

Commit 53234b9

Browse files
committed
Prevent running command more than once
1 parent 588de5d commit 53234b9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

variable_handling.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ var (
2222
ErrMultilineResultCmd = errors.New("Got multiline result from command")
2323
)
2424

25+
var varCmds = make(map[string]string)
26+
2527
func handleDynamicVariableContent(value string) (string, error) {
2628
if value == "" || value[0] != '$' {
2729
return value, nil
2830
}
31+
if result, ok := varCmds[value]; ok {
32+
return result, nil
33+
}
2934
var cmd *exec.Cmd
3035
if ShExists {
3136
cmd = exec.Command(ShPath, "-c", value[1:])
@@ -44,7 +49,9 @@ func handleDynamicVariableContent(value string) (string, error) {
4449
if bytes.ContainsRune(b, '\n') {
4550
return "", ErrMultilineResultCmd
4651
}
47-
return strings.TrimSpace(string(b)), nil
52+
result := strings.TrimSpace(string(b))
53+
varCmds[value] = result
54+
return result, nil
4855
}
4956

5057
func (t *Task) handleVariables() (map[string]string, error) {

0 commit comments

Comments
 (0)