package forgepb import ( "os" "path/filepath" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/lib/protobuf/zoopb" "go.wit.com/log" ) func Init() *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.Warn("forge init() findGoSrc()", err) os.Exit(-1) } 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) } // 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.Info("forgepbb.Init() FORGE_CONFIG", os.Getenv("FORGE_CONFIG")) log.Info("forgepbb.Init() FORGE_GOSRC ", os.Getenv("FORGE_GOSRC"), "f.goWork =", f.IsGoWork()) // cache.go has Do() // f.initOnce.Do(f.initWork) f.Config = new(ForgeConfigs) // load the ~/.config/forge/ config if err := f.Config.ConfigLoad(); err != nil { log.Warn("forgepb.ConfigLoad() failed", err) os.Exit(-1) } f.Repos = new(gitpb.Repos) f.Repos.ConfigLoad() f.Machine = new(zoopb.Machine) if err := f.Machine.ConfigLoad(); err != nil { log.Warn("zoopb.ConfigLoad() failed", err) os.Exit(-1) } f.Machine.InitWit() start := f.Repos.Len() f.ScanGoSrc() end := f.Repos.Len() if (end - start) == 0 { log.Info("Scan of", f.GetGoSrc(), "did not find new git repositories") } else { log.Info("Scan of", f.GetGoSrc(), "Found", end-start, "new git repositories") } return f }