Automatically add envar to help.

See #57.
This commit is contained in:
Alec Thomas
2020-02-19 15:49:59 +11:00
parent b21bf1031a
commit 73ecfde9b2
4 changed files with 40 additions and 0 deletions
+11
View File
@@ -7,6 +7,17 @@ import (
var interpolationRegex = regexp.MustCompile(`((?:\${([[:alpha:]_][[:word:]]*))(?:=([^}]+))?})|(\$)|([^$]+)`)
// Returns true if the variable "v" is interpolated in "s".
func interpolationHasVar(s string, v string) bool {
matches := interpolationRegex.FindAllStringSubmatch(s, -1)
for _, match := range matches {
if name := match[2]; 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 map[string]string) (string, error) {
out := ""