summaryrefslogtreecommitdiff
path: root/init.go
diff options
context:
space:
mode:
Diffstat (limited to 'init.go')
-rw-r--r--init.go154
1 files changed, 52 insertions, 102 deletions
diff --git a/init.go b/init.go
index 9f5dea6..d0f8f03 100644
--- a/init.go
+++ b/init.go
@@ -5,9 +5,9 @@ package forgepb
import (
"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"
@@ -84,87 +84,26 @@ func Init() *Forge {
return f
}
-func DetermineGoPath() *Forge {
- f := new(Forge)
-
- // TODO: rethink this but it works for now
- gosrc := os.Getenv("FORGE_GOSRC")
- if gosrc == "" {
- goSrcDir, err := f.findGoSrc()
- if err != nil {
- log.Log(WARN, "forge init() findGoSrc()", err)
- }
- os.Setenv("FORGE_GOSRC", goSrcDir)
- }
- f.goSrc = os.Getenv("FORGE_GOSRC")
-
- // also rethink this, but maybe this is the right thing to do
- if os.Getenv("FORGE_CONFIG") == "" {
- homeDir, _ := os.UserHomeDir()
- fullpath := filepath.Join(homeDir, ".config/forge")
- os.Setenv("FORGE_CONFIG", fullpath)
- }
-
- f.configDir = os.Getenv("FORGE_CONFIG")
-
- // check again for go.work // user could have a go.work file in ~/go/src
- if f.goWorkExists() {
- f.goWork = true
- }
-
- // print out the settings that will be used
- log.Log(INFO, "forgepb.Init() FORGE_CONFIG", os.Getenv("FORGE_CONFIG"))
-
- return f
-}
-
func (f *Forge) InitPB() {
+ f.setenv()
+
// load the ~/.config/forge/ config
f.Config = new(ForgeConfigs)
- if err := f.Config.ConfigLoad(); err != nil {
+ if err := f.Config.ConfigLoad(f.configDir); err != nil {
log.Log(WARN, "forgepb.ConfigLoad() failed", err)
}
- if f.IsGoWork() {
- log.Log(INFO, "forgepb.Init() FORGE_GOSRC ", os.Getenv("FORGE_GOSRC"), "(go.work = true)")
- } else {
- log.Log(INFO, "forgepb.Init() FORGE_GOSRC ", os.Getenv("FORGE_GOSRC"), "(go.work = false)")
- }
-
f.Repos = gitpb.NewRepos()
f.Repos.ConfigLoad()
if f.Repos.HasFullScan {
f.hasFullScan = true
}
- f.forgeURL = "https://forge.wit.com/"
-
- if os.Getenv("FORGE_URL") != "" {
- f.forgeURL = os.Getenv("FORGE_URL")
- log.Info("got forge url", f.forgeURL)
- }
-
// todo: play with these / determine good values based on user's machine
f.rillX = 10
f.rillY = 20
}
-// set the URL for forge otherwise fallback to ENV or to forge.wit.com
-func (f *Forge) SetForgeURL(url string) {
- if url == "" {
- url = os.Getenv("FORGE_URL")
- }
- if url == "" {
- url = "https://forge.wit.com/"
- }
- f.forgeURL = url
- log.Info("Forge URL has been set to", f.forgeURL)
-}
-
-func (f *Forge) GetForgeURL() string {
- return f.forgeURL
-}
-
func (f *Forge) InitMachine() {
if f.Config.Username == "" {
usr, _ := user.Current()
@@ -176,7 +115,8 @@ func (f *Forge) InitMachine() {
// only init's the protobuf. intended to not scan or change anything
func InitPB() *Forge {
- f := DetermineGoPath()
+ f := new(Forge)
+ f.setenv()
f.InitPB()
return f
}
@@ -197,55 +137,65 @@ func (f *Forge) Exit() {
func RawInitPB() *Forge {
f := new(Forge)
+ f.RawInitPB()
+ return f
+}
- homeDir, _ := os.UserHomeDir()
- // todo: check or exit if err?
-
- // TODO: rethink this but it works for now
- if os.Getenv("FORGE_GOSRC") == "" {
- fullpath := filepath.Join(homeDir, ".cache/forge")
- err := os.MkdirAll(fullpath, os.ModePerm)
- if err != nil {
- log.Log(WARN, "mkdir failed", fullpath, err)
- }
- os.Setenv("FORGE_GOSRC", fullpath)
- }
- f.goSrc = os.Getenv("FORGE_GOSRC")
-
- // also rethink this, but maybe this is the right thing to do
- if os.Getenv("FORGE_CONFIG") == "" {
- fullpath := filepath.Join(homeDir, ".config/forge")
- os.MkdirAll(fullpath, os.ModePerm)
- os.Setenv("FORGE_CONFIG", fullpath)
- }
-
- f.configDir = os.Getenv("FORGE_CONFIG")
+func (f *Forge) RawInitPB() {
+ f.setenv()
// load the ~/.config/forge/ config
f.Config = new(ForgeConfigs)
- if err := f.Config.ConfigLoad(); err != nil {
+ if err := f.Config.ConfigLoad(f.configDir); err != nil {
log.Log(WARN, "forgepb.ConfigLoad() failed", err)
}
f.Repos = gitpb.NewRepos()
f.Repos.ConfigLoad()
- f.forgeURL = "https://forge.wit.com/"
+ // todo: play with these / determine good values based on user's machine
+ f.rillX = 10
+ f.rillY = 20
+}
- if os.Getenv("FORGE_URL") != "" {
- f.forgeURL = os.Getenv("FORGE_URL")
- log.Info("got forge url", 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) setenv() {
+ if err := fhelp.ConfigureENV(); err != nil {
+ log.Info("forge ConfigureENV() failed", err)
+ os.Exit(-1)
}
-
- // where patches are stored
- f.patchDir = f.goSrc
- if os.Getenv("FORGE_PATCHDIR") != "" {
- f.patchDir = os.Getenv("FORGE_PATCHDIR")
+ 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")
+ if os.Getenv("FORGE_GOWORK") == "true" {
+ f.goWork = true
}
+ log.Printf("FORGE_CONFIG = %s\n", f.configDir)
+ log.Printf("FORGE_GOSRC = %s\n", f.goSrc)
+ log.Printf("FORGE_GOWORK = %v\n", f.goWork)
+ log.Printf("FORGE_REPOPB = %s\n", f.repoPB)
+ log.Printf("FORGE_URL = %s\n", f.forgeURL)
+ log.Printf("FORGE_PATCHDIR = %s\n", f.patchDir)
+ log.Printf("HOSTNAME = %s\n", os.Getenv("HOSTNAME"))
+}
- // todo: play with these / determine good values based on user's machine
- f.rillX = 10
- f.rillY = 20
+func (f *Forge) GetForgeURL() string {
+ return f.forgeURL
+}
- return f
+// set the URL for forge otherwise fallback to ENV or to forge.wit.com
+func (f *Forge) SetForgeURL(url string) {
+ if url == "" {
+ url = os.Getenv("FORGE_URL")
+ }
+ if url == "" {
+ url = "https://forge.wit.com/"
+ }
+ f.forgeURL = url
+ os.Setenv("FORGE_URL", f.forgeURL)
+ log.Info("Forge URL has been set to", f.forgeURL)
}