forgepb/init.go

61 lines
1.3 KiB
Go
Raw Normal View History

2024-11-28 00:02:27 -06:00
package forgepb
import (
"os"
2024-12-05 12:37:07 -06:00
"path/filepath"
2024-11-28 00:02:27 -06:00
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"
)
2024-12-01 22:23:02 -06:00
func Init() *Forge {
f := new(Forge)
// TODO: rethink this but it works for now
2024-11-28 00:02:27 -06:00
gosrc := os.Getenv("FORGE_GOSRC")
2024-12-01 22:23:02 -06:00
if gosrc == "" {
2024-11-28 00:02:27 -06:00
// already set. ignore init()
2024-12-01 22:23:02 -06:00
goSrcDir, err := f.findGoSrc()
if err != nil {
log.Warn("forge init() findGoSrc()", err)
}
os.Setenv("FORGE_GOSRC", goSrcDir)
2024-11-28 00:02:27 -06:00
}
2024-12-01 22:23:02 -06:00
f.goSrc = os.Getenv("FORGE_GOSRC")
2024-11-28 23:00:29 -06:00
2024-12-05 12:37:07 -06:00
// 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)
}
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)
}
2024-12-06 01:50:03 -06:00
f.Machine.InitWit()
2024-11-28 21:03:51 -06:00
2024-12-05 12:37:07 -06:00
start := f.Repos.Len()
2024-11-28 08:35:39 -06:00
f.ScanGoSrc()
2024-12-05 12:37:07 -06:00
end := f.Repos.Len()
log.Info("forge.ScanGoSrc() Found", end-start, "new repos in", f.goSrc)
2024-11-28 18:36:15 -06:00
return f
2024-11-28 00:02:27 -06:00
}