forgepb/init.go

54 lines
1.0 KiB
Go
Raw Normal View History

2024-11-28 00:02:27 -06:00
package forgepb
import (
"os"
2024-11-28 08:35:39 -06:00
"go.wit.com/lib/protobuf/gitpb"
2024-11-28 19:56:46 -06:00
"go.wit.com/lib/protobuf/zoopb"
2024-11-28 00:02:27 -06:00
"go.wit.com/log"
)
// set FORGE_GOSRC env if not already set
func init() {
gosrc := os.Getenv("FORGE_GOSRC")
if gosrc != "" {
// already set. ignore init()
}
2024-11-28 08:35:39 -06:00
goSrcDir, err := FindGoSrc()
2024-11-28 00:02:27 -06:00
if err != nil {
2024-11-28 08:35:39 -06:00
log.Warn("forge init() FindGoSrc()", err)
panic("forge init() FindGoSrc()")
2024-11-28 00:02:27 -06:00
}
2024-11-28 08:35:39 -06:00
os.Setenv("FORGE_GOSRC", goSrcDir)
2024-11-28 00:02:27 -06:00
}
2024-11-28 18:36:15 -06:00
func Init() *Forge {
f := new(Forge)
2024-11-28 23:00:29 -06:00
// cache.go has Do()
// f.initOnce.Do(f.initWork)
2024-11-28 18:36:15 -06:00
f.Config = new(ForgeConfigs)
2024-11-28 00:02:27 -06:00
// load the ~/.config/forge/ config
if err := f.Config.ConfigLoad(); err != nil {
log.Warn("forgepb.ConfigLoad() failed", err)
os.Exit(-1)
}
2024-11-28 08:35:39 -06:00
2024-11-28 19:56:46 -06:00
f.Repos = new(gitpb.Repos)
2024-12-01 10:44:29 -06:00
f.Repos.ConfigLoad()
2024-11-28 19:56:46 -06:00
f.Machine = new(zoopb.Machine)
2024-11-28 08:35:39 -06:00
2024-11-28 21:03:51 -06:00
if err := f.Machine.ConfigLoad(); err != nil {
log.Warn("zoopb.ConfigLoad() failed", err)
os.Exit(-1)
}
f.Machine.InitWit()
2024-11-28 08:35:39 -06:00
f.goSrc = os.Getenv("FORGE_GOSRC")
f.ScanGoSrc()
2024-11-30 12:45:07 -06:00
log.Info("forge.Init() found", f.Repos.Len(), "repos in", f.goSrc)
2024-11-28 18:36:15 -06:00
return f
2024-11-28 00:02:27 -06:00
}