Browse Source

in hooks, allow replacing placeholders with environment (#3044)

pull/3049/head
Dan Bason 1 year ago committed by GitHub
parent
commit
e8b19b82d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 11
      internal/externalcmd/cmd.go

11
internal/externalcmd/cmd.go

@ -4,7 +4,7 @@ package externalcmd
import ( import (
"errors" "errors"
"fmt" "fmt"
"strings" "os"
"time" "time"
) )
@ -42,10 +42,15 @@ func NewCmd(
) *Cmd { ) *Cmd {
// replace variables in both Linux and Windows, in order to allow using the // replace variables in both Linux and Windows, in order to allow using the
// same commands on both of them. // same commands on both of them.
for key, val := range env { expandEnv := func(variable string) string {
cmdstr = strings.ReplaceAll(cmdstr, "$"+key, val) if value, ok := env[variable]; ok {
return value
}
return os.Getenv(variable)
} }
cmdstr = os.Expand(cmdstr, expandEnv)
if onExit == nil { if onExit == nil {
onExit = func(_ error) {} onExit = func(_ error) {}
} }

Loading…
Cancel
Save