diff options
| -rw-r--r-- | SetGlobal.go | 22 | ||||
| -rw-r--r-- | formatENV.go | 5 | ||||
| -rw-r--r-- | key.proto | 4 | ||||
| -rw-r--r-- | save.go | 10 | ||||
| -rw-r--r-- | table.go | 46 |
5 files changed, 79 insertions, 8 deletions
diff --git a/SetGlobal.go b/SetGlobal.go new file mode 100644 index 0000000..f255dcd --- /dev/null +++ b/SetGlobal.go @@ -0,0 +1,22 @@ +package ENV + +import "errors" + +func SetGlobal(global string, varname string, newValue string) error { + if envPB == nil { + return NotInitialized + } + saveMu.Lock() + defer saveMu.Unlock() + found := envPB.FindByVar(varname) + if found != nil { + return errors.New("already set") + } + + newvar := new(Key) + newvar.Var = varname + newvar.Value = newValue + newvar.Global = global + envPB.Append(newvar) + return nil +} diff --git a/formatENV.go b/formatENV.go index 0d1efc3..3718b1f 100644 --- a/formatENV.go +++ b/formatENV.go @@ -16,6 +16,7 @@ func formatENV() (string, error) { var out string uniques := make(map[string]*Key) // check to make sure there are no duplicate entries + // todo: remove this duplicate entry check once duplicates aren't a problem anymore for c := range envPB.IterAll() { key := strings.ToLower(c.Var) if len(strings.Fields(key)) != 1 { @@ -35,6 +36,10 @@ func formatENV() (string, error) { log.Info("key has nil c", key) continue } + if c.Global != "" { + // don't write out anything defined globally + continue + } line := fmt.Sprintf("%s=%s", c.Var, c.Value) out += line + "\n" } @@ -7,11 +7,11 @@ package ENV; message Key { // string var = 1; // ENV var name `autogenpb:unique` `autogenpb:sort` string value = 2; // ENV value name - bool global = 3; // was defined in application OS settings + string global = 3; // where ENV was defined in application OS settings string help = 4; // text for explaining the ENV key/value } -message Keys { // `autogenpb:marshal` `autogenpb:nomutex` +message Keys { // `autogenpb:marshal` `autogenpb:nomutex` `autogenpb:gui` string uuid = 1; // `autogenpb:uuid:7a8aaf7f-9851-42f0-89eb-434d2e51f5bb` string version = 2; // `autogenpb:version:v0.0.1 go.wit.com/lib/ENV` repeated Key keys = 3; @@ -3,8 +3,6 @@ package ENV import ( "os" "strings" - - "go.wit.com/log" ) // saves your applications config file @@ -25,10 +23,10 @@ func saveENV() error { func saveENVnolock(filename string) error { outENV, err := formatENV() if err == nil { - log.Info("SAVEENV IS RUNNING") - log.Info("SAVEENV IS RUNNING") - log.Info("SAVEENV IS RUNNING") - log.Info(outENV) + // log.Info("SAVEENV IS RUNNING") + // log.Info("SAVEENV IS RUNNING") + // log.Info("SAVEENV IS RUNNING") + // log.Info(outENV) } return os.WriteFile(filename, []byte(outENV), 0644) } diff --git a/table.go b/table.go new file mode 100644 index 0000000..c7afec8 --- /dev/null +++ b/table.go @@ -0,0 +1,46 @@ +// Copyright 2025 WIT.COM Inc Licensed GPL 3.0 + +package ENV + +import ( + "go.wit.com/log" +) + +func PrintTable() string { + t := envPB.MakeTable("ENV table") + + // limit the number of lines + t.PrintTable() + return log.Sprintf("ENV: total=(%d)", envPB.Len()) +} + +func (pb *Keys) MakeTable(name string) *KeysTable { + t := pb.NewTable(name) + t.NewUuid() + + var col *KeyFunc + + col = t.AddStringFunc("Source", func(k *Key) string { + return k.Global + }) + col.Width = 20 + + col = t.AddVar() + col.Width = 20 + + col = t.AddValue() + col.Width = -1 + // col.Header.Name = "Git Hash" + + /* + col = t.AddStringFunc("age", func(r *Key) string { + return cobol.Time(r.Ctime) + }) + col.Width = 28 + + col = t.AddSubject() + col.Width = -1 + */ + + return t +} |
