diff options
| author | Jeff Carr <[email protected]> | 2024-11-28 00:02:27 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-28 00:02:27 -0600 |
| commit | 0401b949c6f900891f1eefaba41295d2c2a96b07 (patch) | |
| tree | b95a0a23fe444e212ab873f90b2f347303785b56 /init.go | |
| parent | 54a93cd5ebbaf7ed72704c1af9a8be5b8c71f5bd (diff) | |
added Init() and a Forge struct
Diffstat (limited to 'init.go')
| -rw-r--r-- | init.go | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -0,0 +1,41 @@ +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() +} |
