diff options
Diffstat (limited to 'init.go')
| -rw-r--r-- | init.go | 51 |
1 files changed, 45 insertions, 6 deletions
@@ -11,6 +11,7 @@ import ( "go.wit.com/lib/cobol" "go.wit.com/lib/config" "go.wit.com/lib/env" + "go.wit.com/lib/fhelp" "go.wit.com/log" ) @@ -61,6 +62,44 @@ func (f *Forge) Close() error { } func (f *Forge) postInit() error { + cache := "auto" + if env.Get("cache") == "" { + // leave "auto" by default + } else { + // get the users default preference + cache = env.Get("cache") + } + + // if cache is set to "auto", this detects if you are in a + // a golang directory (~/go/src) or in a dir that has a "go.work" file + if cache == "auto" { + if godir, ok := fhelp.FindGoWork(); ok { + f.mode = ForgeMode_GOLANG + cache = "gowork" + env.SetGlobal("lib/forgepb", "gopath", godir) + fullname := filepath.Join(godir, "gowork.pb") + env.SetGlobal("lib/forgepb", "ReposPB", fullname) + } else { + gopath := filepath.Join(env.Get("homedir"), "go/src") + + pwd, err := os.Getwd() + if err == nil { + _, err := filepath.Rel(gopath, pwd) + if err == nil { + f.mode = ForgeMode_GOLANG + // user is running forge from within ~/go/src + env.SetGlobal("lib/forgepb", "gopath", gopath) + cache = "gosrc" + } + } + // always define + if env.Get("gopath") == "" { + env.SetGlobal("lib/forgepb", "gopath", gopath) + } + } + } + f.configureCache(cache) + // always define if env.Get("username") == "" { usr, _ := user.Current() @@ -76,12 +115,6 @@ func (f *Forge) postInit() error { } // always define - if env.Get("gopath") == "" { - gopath := filepath.Join(env.Get("homedir"), "go/src") - env.SetGlobal("lib/forgepb", "gopath", gopath) - } - - // always define if env.Get("curpatches") == "" { env.SetGlobal("lib/forgepb", "curpatches", "curpatches.pb") } @@ -90,10 +123,16 @@ func (f *Forge) postInit() error { switch env.Get("Mode") { case "NORMAL": f.mode = ForgeMode_NORMAL + case "CUSTOM": + f.mode = ForgeMode_CUSTOM + case "GOLANG": + f.mode = ForgeMode_GOLANG case "CLEAN": f.mode = ForgeMode_CLEAN case "MASTER": f.mode = ForgeMode_MASTER + case "DEVEL": + f.mode = ForgeMode_DEVEL default: f.mode = ForgeMode_NEWUSER } |
