1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/builder/evaluator/support.go
Erik Hollensbe 1ae4c00a19 builder: fix references to jobs in daemon, make builder a first class
package referring to evaluator

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)
2014-08-27 18:52:30 -07:00

26 lines
574 B
Go

package evaluator
import (
"regexp"
"strings"
)
var (
TOKEN_ENV_INTERPOLATION = regexp.MustCompile("(\\\\\\\\+|[^\\\\]|\\b|\\A)\\$({?)([[:alnum:]_]+)(}?)")
)
// handle environment replacement. Used in dispatcher.
func replaceEnv(b *BuildFile, str string) string {
for _, match := range TOKEN_ENV_INTERPOLATION.FindAllString(str, -1) {
match = match[strings.Index(match, "$"):]
matchKey := strings.Trim(match, "${}")
for envKey, envValue := range b.Env {
if matchKey == envKey {
str = strings.Replace(str, match, envValue, -1)
}
}
}
return str
}