grim/convey

Parents 5455207816fd
Children ee239409c3de
Add the recursive environment expanding back with a much simplier algorithm
--- a/environment/expand.go Mon Oct 11 06:21:30 2021 -0500
+++ b/environment/expand.go Mon Oct 11 06:53:39 2021 -0500
@@ -2,6 +2,8 @@
import (
"os"
+
+ log "github.com/sirupsen/logrus"
)
func (e Environment) expandMapper(name string) string {
@@ -27,7 +29,20 @@
// Expand looks for the given key and returns the value if one is found
// recursing if the value contains another variable.
func (e Environment) Expand(key string) string {
- return os.Expand(key, e.expandMapper)
+ last := os.Expand(key, e.expandMapper)
+ n_tries := 10
+
+ for i := 0; i < n_tries; i++ {
+ next := os.Expand(last, e.expandMapper)
+ if next == last {
+ return next
+ }
+ last = next
+ }
+
+ log.Warnf("failed to fully expand %q after %d recursions", key, n_tries)
+
+ return ""
}
func (e Environment) Expandv(items []string) []string {