⬆️ Update dependencies
This commit is contained in:
+17
-4
@@ -5,7 +5,18 @@ import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var interpolationRegex = regexp.MustCompile(`((?:\${([[:alpha:]_][[:word:]]*))(?:=([^}]+))?})|(\$)|([^$]+)`)
|
||||
var interpolationRegex = regexp.MustCompile(`(\$\$)|((?:\${([[:alpha:]_][[:word:]]*))(?:=([^}]+))?})|(\$)|([^$]+)`)
|
||||
|
||||
// HasInterpolatedVar returns true if the variable "v" is interpolated in "s".
|
||||
func HasInterpolatedVar(s string, v string) bool {
|
||||
matches := interpolationRegex.FindAllStringSubmatch(s, -1)
|
||||
for _, match := range matches {
|
||||
if name := match[3]; name == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Interpolate variables from vars into s for substrings in the form ${var} or ${var=default}.
|
||||
func interpolate(s string, vars Vars, updatedVars map[string]string) (string, error) {
|
||||
@@ -21,14 +32,16 @@ func interpolate(s string, vars Vars, updatedVars map[string]string) (string, er
|
||||
}
|
||||
}
|
||||
for _, match := range matches {
|
||||
if name := match[2]; name != "" {
|
||||
if dollar := match[1]; dollar != "" {
|
||||
out += "$"
|
||||
} else if name := match[3]; name != "" {
|
||||
value, ok := vars[name]
|
||||
if !ok {
|
||||
// No default value.
|
||||
if match[3] == "" {
|
||||
if match[4] == "" {
|
||||
return "", fmt.Errorf("undefined variable ${%s}", name)
|
||||
}
|
||||
value = match[3]
|
||||
value = match[4]
|
||||
}
|
||||
out += value
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user