From 200b76da8a0dd95b524d44e90a92106a9699d9fd Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 28 Oct 2025 21:59:48 -0500 Subject: allow libraries to load a specific app env config file --- etc.go | 10 ++++------ init.go | 14 ++++++++++++++ path.go | 9 ++++----- verbose.go | 6 ++++++ 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 } -- cgit v1.2.3