summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-28 21:59:48 -0500
committerJeff Carr <[email protected]>2025-10-28 21:59:48 -0500
commit200b76da8a0dd95b524d44e90a92106a9699d9fd (patch)
treefbd9110e1b464278c5b9faa93639fe887494effd
parent05d09b7584b4cd18676c68dd161142044437a7af (diff)
allow libraries to load a specific app env config fileHEADv0.0.13v0.0.12v0.0.11masterdevel
-rw-r--r--etc.go10
-rw-r--r--init.go14
-rw-r--r--path.go9
-rw-r--r--verbose.go6
4 files changed, 28 insertions, 11 deletions
diff --git a/etc.go b/etc.go
index 4e7e7ec..9f6846d 100644
--- a/etc.go
+++ b/etc.go
@@ -5,14 +5,12 @@ import (
"os"
"path/filepath"
"strings"
-
- "go.wit.com/log"
)
var ErrInit error = fmt.Errorf("lib/env has not been initialized")
func LoadEtc() error {
- log.Info("Starting LoadEtc() with appname:", APPNAME)
+ fmt.Printf("Starting LoadEtc() with appname: %s\n", APPNAME)
if envPB == nil {
return ErrInit
}
@@ -21,19 +19,19 @@ func LoadEtc() error {
}
globPattern := filepath.Join("/etc/", APPNAME+".d", "*")
- log.Info("glob Pattern:", globPattern)
+ fmt.Printf("glob Pattern (%s)\n", globPattern)
files, err := filepath.Glob(globPattern)
if err != nil {
fmt.Printf("%s glob error (%v)\n", globPattern, err)
return err
}
- log.Info("found files:", files)
+ fmt.Printf("found files: %v\n", files)
for _, file := range files {
data, _ := os.ReadFile(file)
_, name := filepath.Split(file)
parseFileData("etc/"+name, string(data))
- log.Info("LoadEtc() file:", file)
+ fmt.Println("LoadEtc() file:", file)
}
return nil
diff --git a/init.go b/init.go
index 4db6315..c595dfa 100644
--- a/init.go
+++ b/init.go
@@ -131,3 +131,17 @@ func LoadENV(filename string) error {
}
return err
}
+
+func LoadAppENV(appname string) error {
+ configDir, err := os.UserConfigDir()
+ if err != nil {
+ return err
+ }
+ fpath := filepath.Join(configDir, appname, appname+"rc")
+ fmt.Printf("env.Load(%s)\n", fpath)
+ data, err := os.ReadFile(fpath)
+ if err == nil {
+ parseFileData(appname, string(data))
+ }
+ return err
+}
diff --git a/path.go b/path.go
index 66a27fe..b9fffdb 100644
--- a/path.go
+++ b/path.go
@@ -1,25 +1,24 @@
package env
import (
+ "fmt"
"os"
"path/filepath"
"strings"
-
- "go.wit.com/log"
)
// adds a path to the ENV
func AddPath(newpath string) bool {
path := os.Getenv("PATH")
for _, p := range strings.Split(path, ":") {
- log.Info("Looking at path:", p)
+ fmt.Println("Looking at path:", p)
if p == newpath {
- log.Info("FOUND path:", p)
+ fmt.Println("FOUND path:", p)
return false
}
}
path = path + ":" + newpath
- log.Info("ADDING PATH:", path)
+ fmt.Println("ADDING PATH:", path)
os.Setenv("PATH", path)
return true
}
diff --git a/verbose.go b/verbose.go
index e3aba43..bcccf70 100644
--- a/verbose.go
+++ b/verbose.go
@@ -1,5 +1,7 @@
package env
+import "os"
+
// this is an experiment at this point to
// see how this turns out
@@ -25,6 +27,10 @@ func Verbose() bool {
return true
}
}
+
+ if os.Getenv("VERBOSE") == "true" {
+ return true
+ }
return false
}