57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package forgepb
|
|
|
|
import (
|
|
"os"
|
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
|
"go.wit.com/lib/protobuf/zoopb"
|
|
"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()
|
|
}
|
|
goSrcDir, err := FindGoSrc()
|
|
if err != nil {
|
|
log.Warn("forge init() FindGoSrc()", err)
|
|
panic("forge init() FindGoSrc()")
|
|
}
|
|
os.Setenv("FORGE_GOSRC", goSrcDir)
|
|
}
|
|
|
|
func Init() *Forge {
|
|
f := new(Forge)
|
|
|
|
// 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.Machine = new(zoopb.Machine)
|
|
|
|
if err := f.Machine.ConfigLoad(); err != nil {
|
|
log.Warn("zoopb.ConfigLoad() failed", err)
|
|
os.Exit(-1)
|
|
}
|
|
f.Machine.InitWit()
|
|
|
|
f.goSrc = os.Getenv("FORGE_GOSRC")
|
|
f.ScanGoSrc()
|
|
log.Warn("GOT HERE. forge.Init(). f can not be nil")
|
|
return f
|
|
}
|
|
|
|
func (f *Forge) SortByPath() *ForgeConfigIterator {
|
|
return f.Config.SortByPath()
|
|
}
|