summaryrefslogtreecommitdiff
path: root/init.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-27 00:26:10 -0500
committerJeff Carr <[email protected]>2025-10-27 00:26:10 -0500
commitdbe78b785508d8ef665d8b9c4d61e4dd8eb40e51 (patch)
treee25ef3eb97a435318f6e52a3709e3625ed20561c /init.go
parent4d0828def125f96d376cc1bd018bd3d8b0997901 (diff)
add some more details. not much more to do here.
Diffstat (limited to 'init.go')
-rw-r--r--init.go40
1 files changed, 33 insertions, 7 deletions
diff --git a/init.go b/init.go
index 2db551c..8868309 100644
--- a/init.go
+++ b/init.go
@@ -24,6 +24,7 @@ func Init(appname, version, buildtime string, fromargv []string, goodFunc func(s
}
envPB = NewKeys()
envPB.Init = true
+ envPB.HomeDir, _ = os.UserHomeDir()
loadAppENV()
@@ -34,16 +35,14 @@ func Init(appname, version, buildtime string, fromargv []string, goodFunc func(s
if err == nil {
SetGlobal("lib/env", "username", usr.Username)
}
- homeDir, err := os.UserHomeDir()
+ homedir, err := os.UserHomeDir()
if err == nil {
- SetGlobal("lib/env", "homeDir", homeDir)
+ SetGlobal("lib/env", "homedir", homedir)
}
}
// if it exists, loads ~/.config/<appname>/<appname>rc
func loadAppENV() error {
- saveMu.Lock()
- saveMu.Unlock()
configDir, err := os.UserConfigDir()
if err != nil {
return err
@@ -74,11 +73,19 @@ func InitValid() bool {
return envPB.Init
}
+// only allow super simple files
func parseENV(data string) {
+ var helptext string
// fmt.Println("loadENV()", filename)
for _, line := range strings.Split(data, "\n") {
line = strings.TrimSpace(line)
if line == "" {
+ // ignore empty lines
+ continue
+ }
+ if strings.HasPrefix(line, "#") {
+ // save notes & instructions from the config file
+ helptext += line + "\n"
continue
}
parts := strings.Split(line, "=")
@@ -86,10 +93,29 @@ func parseENV(data string) {
// fmt.Println("INVALID LINE:", i, line)
continue
}
+ varname := parts[0]
+ varname = strings.TrimSpace(varname)
+ if varname == "" {
+ // ignore empty varname
+ continue
+ }
+
+ // check for duplicates here
+ found := envPB.FindByVar(varname)
+ if found != nil {
+ // varname alrady set
+ continue
+ }
+
+ value := parts[1]
+ value = strings.Trim(value, "'\"")
+ saveMu.Lock()
+ saveMu.Unlock()
c := new(Key)
- c.Var = parts[0]
- c.Value = parts[1]
+ c.Var = varname
+ c.Value = value
+ c.Help = helptext
+ helptext = ""
envPB.Append(c)
- // fmt.Printf("ENV LINE: (%v)\n", c)
}
}