2014-08-15 16:29:35 +00:00
|
|
|
package builder
|
2014-08-05 20:17:40 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
TOKEN_ENV_INTERPOLATION = regexp.MustCompile("(\\\\\\\\+|[^\\\\]|\\b|\\A)\\$({?)([[:alnum:]_]+)(}?)")
|
|
|
|
)
|
|
|
|
|
2014-08-07 05:56:44 +00:00
|
|
|
// handle environment replacement. Used in dispatcher.
|
2014-08-26 19:25:44 +00:00
|
|
|
func (b *Builder) replaceEnv(str string) string {
|
2014-08-05 20:17:40 +00:00
|
|
|
for _, match := range TOKEN_ENV_INTERPOLATION.FindAllString(str, -1) {
|
|
|
|
match = match[strings.Index(match, "$"):]
|
|
|
|
matchKey := strings.Trim(match, "${}")
|
|
|
|
|
2014-08-13 10:07:41 +00:00
|
|
|
for _, keyval := range b.Config.Env {
|
|
|
|
tmp := strings.SplitN(keyval, "=", 2)
|
|
|
|
if tmp[0] == matchKey {
|
|
|
|
str = strings.Replace(str, match, tmp[1], -1)
|
2014-08-19 11:14:21 +00:00
|
|
|
break
|
2014-08-05 20:17:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return str
|
|
|
|
}
|
2014-08-13 10:07:41 +00:00
|
|
|
|
|
|
|
func handleJsonArgs(args []string, attributes map[string]bool) []string {
|
2014-08-30 11:34:09 +00:00
|
|
|
if len(args) == 0 {
|
|
|
|
return []string{}
|
|
|
|
}
|
|
|
|
|
2014-08-13 10:07:41 +00:00
|
|
|
if attributes != nil && attributes["json"] {
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
|
|
|
// literal string command, not an exec array
|
2014-08-30 11:34:09 +00:00
|
|
|
return []string{strings.Join(args, " ")}
|
2014-08-13 10:07:41 +00:00
|
|
|
}
|