summaryrefslogtreecommitdiff
path: root/formatENV.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-21 06:40:48 -0500
committerJeff Carr <[email protected]>2025-10-21 06:40:48 -0500
commit3cf635e3c41be385b50778f7818fd50b006f1671 (patch)
treedba1a8c80e363d4f86a5f81623bc1f603e39318e /formatENV.go
parent4d3349c453879051a7499fa07a97dfcb20b554ea (diff)
something to act like bash ENV
Diffstat (limited to 'formatENV.go')
-rw-r--r--formatENV.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/formatENV.go b/formatENV.go
new file mode 100644
index 0000000..0d1efc3
--- /dev/null
+++ b/formatENV.go
@@ -0,0 +1,51 @@
+package ENV
+
+import (
+ "errors"
+ "fmt"
+ "strings"
+
+ "go.wit.com/log"
+)
+
+func formatENV() (string, error) {
+ if envPB == nil {
+ return "", errors.New("envPB not initialized")
+ }
+
+ var out string
+ uniques := make(map[string]*Key) // check to make sure there are no duplicate entries
+
+ for c := range envPB.IterAll() {
+ key := strings.ToLower(c.Var)
+ if len(strings.Fields(key)) != 1 {
+ log.Info("dropping invalid key = ", c.Var, "value =", c.Value)
+ continue
+ }
+ found := findByLower(key)
+ if found == nil {
+ log.Info("findByKey() got nil for key:", key)
+ }
+ // todo: warn about duplicates?
+ uniques[key] = found
+ }
+
+ for key, c := range uniques {
+ if c == nil {
+ log.Info("key has nil c", key)
+ continue
+ }
+ line := fmt.Sprintf("%s=%s", c.Var, c.Value)
+ out += line + "\n"
+ }
+ return out, nil
+}
+
+func findByLower(lookingFor string) *Key {
+ for c := range envPB.IterAll() {
+ if strings.ToLower(c.Var) == strings.ToLower(lookingFor) {
+ return c
+ }
+ }
+ return nil
+}