move CloneWith() call into interpolate()

This commit is contained in:
Will Roden
2020-05-15 16:36:04 -05:00
committed by Alec Thomas
parent f19cb8c69d
commit 7bdb319cf1
3 changed files with 24 additions and 14 deletions
+10 -1
View File
@@ -8,9 +8,18 @@ import (
var interpolationRegex = regexp.MustCompile(`((?:\${([[:alpha:]_][[:word:]]*))(?:=([^}]+))?})|(\$)|([^$]+)`)
// Interpolate variables from vars into s for substrings in the form ${var} or ${var=default}.
func interpolate(s string, vars map[string]string) (string, error) {
func interpolate(s string, vars Vars, updatedVars map[string]string) (string, error) {
out := ""
matches := interpolationRegex.FindAllStringSubmatch(s, -1)
if len(matches) == 0 {
return s, nil
}
for key, val := range updatedVars {
if vars[key] != val {
vars = vars.CloneWith(updatedVars)
break
}
}
for _, match := range matches {
if name := match[2]; name != "" {
value, ok := vars[name]