forgepb/init.go

42 lines
810 B
Go
Raw Normal View History

2024-11-28 00:02:27 -06:00
package forgepb
import (
"os"
"path/filepath"
"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()
}
homeDir, err := os.UserHomeDir()
if err != nil {
log.Warn("forge init() could not find UserHomeDir()", err)
panic("forge could not find UserHomeDir")
}
fullpath := filepath.Join(homeDir, "go/src")
os.Setenv("FORGE_GOSRC", fullpath)
}
func (f *Forge) Init() {
if f == nil {
f = new(Forge)
}
if f.Config == nil {
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)
}
}
func (f *Forge) SortByPath() *ForgeConfigIterator {
return f.Config.SortByPath()
}