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 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)
|
|
|
|
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
|
|
|
|
|
|
|
if f.Repos == nil {
|
|
|
|
f.Repos = new(gitpb.Repos)
|
|
|
|
}
|
|
|
|
|
|
|
|
f.goSrc = os.Getenv("FORGE_GOSRC")
|
|
|
|
f.ScanGoSrc()
|
2024-11-28 18:36:15 -06:00
|
|
|
log.Warn("GOT HERE. forge.Init(). f can not be nil")
|
|
|
|
return f
|
2024-11-28 00:02:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Forge) SortByPath() *ForgeConfigIterator {
|
|
|
|
return f.Config.SortByPath()
|
|
|
|
}
|