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