This doesn't really take much advantage of structured logging beyond what is already done (`id` and `idColor`), and consequently the log handler does not try to do any handling of anything more than that (i.e., grouping, or arbitrary attributes beyond those defined).
One should maybe have a `Context` available to pass in, but there isn't one, and anyway, the log handler doesn't use it, so I've passed in a `TODO` instead.
Everything else is just normal import/rename changes.
Testing Done:
Ran `go run . run`
Reviewed at https://reviews.imfreedom.org/r/2871/
packageenvironment
import(
"fmt"
"log/slog"
"os"
)
func(eEnvironment)expandMapper(namestring)string{
// We might have something like $(pwd), in which case we don't want
// to wrap the name in `{}`, which would cause it to be ${}(pwd) and
// cannot be evaluated by a run task.
ifname==""{
return"$"
}
ifval,found:=e[name];found{
ifval!=""{
returnval
}
returnos.Getenv(name)
}
return""
}
// Expand looks for the given key and returns the value if one is found
// recursing if the value contains another variable.
func(eEnvironment)Expand(keystring)string{
last:=os.Expand(key,e.expandMapper)
tries:=10
fori:=0;i<tries;i++{
next:=os.Expand(last,e.expandMapper)
ifnext==last{
returnnext
}
last=next
}
slog.Warn(fmt.Sprintf("failed to fully expand %q after %d recursions",key,tries))