summaryrefslogtreecommitdiff
path: root/init.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-11 01:53:53 -0500
committerJeff Carr <[email protected]>2025-09-11 01:53:53 -0500
commitdbde2f51b8acb4043203b5592531c6715896c800 (patch)
treebb892866022b2f8045784091b181592dc480b3c8 /init.go
parentac107331fc376edc5343732f7ebcd0d8e3177282 (diff)
cleanup config file handling
Diffstat (limited to 'init.go')
-rw-r--r--init.go99
1 files changed, 75 insertions, 24 deletions
diff --git a/init.go b/init.go
index 5205e4b..a8fc63c 100644
--- a/init.go
+++ b/init.go
@@ -3,14 +3,10 @@
package forgepb
import (
- "errors"
"os"
"os/user"
- "path/filepath"
- "time"
"go.wit.com/lib/fhelp"
- "go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
@@ -25,15 +21,10 @@ func Default(opts ...OptionFunc) *Engine {
}
*/
+/*
func Init() *Forge {
f := InitPB()
- /*
- f.Machine = new(zoopb.Machine)
- if err := f.Machine.ConfigLoad(); err != nil {
- log.Log(WARN, "zoopb.ConfigLoad() failed", err)
- }
- */
if f.Config.Username == "" {
usr, _ := user.Current()
f.Config.Username = usr.Username
@@ -82,24 +73,31 @@ func Init() *Forge {
log.Log(INFO, "update() check took", shell.FormatDuration(time.Since(now)))
return f
}
+*/
-func FirstTimeUser() bool {
- if checkenv() {
- return false
- }
-
- // setup the env
+func InitFromConfig(cfg *ForgeConfigs) *Forge {
f := new(Forge)
- f.setenv()
+ f.Config = cfg
+ if f.configENV() {
+ log.Info("ENV changed config. todo: save config here")
+ }
- fullname := filepath.Join(os.Getenv("FORGE_CONFIG"), "forge.text")
- _, err := os.ReadFile(fullname)
- if errors.Is(err, os.ErrNotExist) {
- return true
+ f.Repos = gitpb.NewRepos()
+ f.Repos.ConfigLoad()
+ if f.Repos.HasFullScan {
+ f.hasFullScan = true
}
- return false
+
+ // init the Patchsets
+ f.Patchsets = NewPatchsets()
+
+ // todo: play with these / determine good values based on user's machine
+ f.rillX = 10
+ f.rillY = 20
+ return f
}
+/*
func (f *Forge) InitPB() {
f.setenv()
@@ -122,6 +120,7 @@ func (f *Forge) InitPB() {
f.rillX = 10
f.rillY = 20
}
+*/
func (f *Forge) InitMachine() {
if f.Config.Username == "" {
@@ -132,6 +131,7 @@ func (f *Forge) InitMachine() {
// log.Info(hostname, err)
}
+/*
// only init's the protobuf. intended to not scan or change anything
func InitPB() *Forge {
f := new(Forge)
@@ -139,6 +139,7 @@ func InitPB() *Forge {
f.InitPB()
return f
}
+*/
func (f *Forge) SetConfigSave(b bool) {
f.configSave = b
@@ -154,6 +155,7 @@ func (f *Forge) Exit() {
os.Exit(0)
}
+/*
func RawInitPB() *Forge {
f := new(Forge)
f.RawInitPB()
@@ -163,6 +165,7 @@ func RawInitPB() *Forge {
func (f *Forge) RawInitPB() {
f.InitPB()
}
+*/
// the first thing done is process any ENV settings
// try to NOT use the ENV settings anywhere but here
@@ -173,15 +176,20 @@ func (f *Forge) setenv() {
log.Info("forge ConfigureENV() failed", err)
os.Exit(-1)
}
+ if f.Config == nil {
+ log.Info("forge.Config() was nil")
+ os.Exit(-1)
+ }
f.configDir = os.Getenv("FORGE_CONFIG")
f.goSrc = os.Getenv("FORGE_GOSRC")
- f.repoPB = os.Getenv("FORGE_REPOPB")
f.forgeURL = os.Getenv("FORGE_URL")
- f.patchDir = os.Getenv("FORGE_PATCHDIR")
f.hostname = os.Getenv("HOSTNAME")
if os.Getenv("FORGE_GOWORK") == "true" {
f.goWork = true
}
+
+ f.Config.ReposPB = os.Getenv("FORGE_REPOPB")
+ f.Config.PatchDir = os.Getenv("FORGE_PATCHDIR")
})
}
@@ -224,3 +232,46 @@ func (f *Forge) SetForgeURL(url string) {
os.Setenv("FORGE_URL", f.forgeURL)
log.Info("Forge URL has been set to", f.forgeURL)
}
+
+// the first thing done is process any ENV settings
+// try to NOT use the ENV settings anywhere but here
+// all initial ENV settings should be stored in the forge struct
+func (f *Forge) configENV() bool {
+ var changed bool
+ f.once.Do(func() {
+ if err := fhelp.ConfigureENV(); err != nil {
+ log.Info("forge ConfigureENV() failed", err)
+ os.Exit(-1)
+ }
+ if os.Getenv("FORGE_REPOPB") != "" && f.Config.ReposPB != os.Getenv("FORGE_REPOPB") {
+ log.Info("ENV: updating FORGE_REPOSPB from", f.Config.ReposPB, "to", os.Getenv("FORGE_REPOPB"))
+ f.Config.ReposPB = os.Getenv("FORGE_REPOPB")
+ changed = true
+ }
+
+ if os.Getenv("FORGE_GOSRC") != "" && f.Config.ReposDir != os.Getenv("FORGE_GOSRC") {
+ log.Info("ENV: updating FORGE_GOSRC from", f.Config.ReposDir, "to", os.Getenv("FORGE_GOSRC"))
+ f.Config.ReposDir = os.Getenv("FORGE_GOSRC")
+ changed = true
+ }
+
+ if os.Getenv("FORGE_PATCHDIR") != "" && f.Config.PatchDir != os.Getenv("FORGE_PATCHDIR") {
+ log.Info("ENV: updating FORGE_PATCHDIR from", f.Config.PatchDir, "to", os.Getenv("FORGE_PATCHDIRC"))
+ f.Config.PatchDir = os.Getenv("FORGE_PATCHDIR")
+ changed = true
+ }
+
+ f.configDir = os.Getenv("FORGE_CONFIG")
+ f.goSrc = os.Getenv("FORGE_GOSRC")
+ f.forgeURL = os.Getenv("FORGE_URL")
+ // f.patchDir = os.Getenv("FORGE_PATCHDIR")
+ f.hostname = os.Getenv("HOSTNAME")
+ if os.Getenv("FORGE_GOWORK") == "true" {
+ f.goWork = true
+ }
+ })
+ if changed {
+ // save config here
+ }
+ return changed
+}