summaryrefslogtreecommitdiff
path: root/init.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-28 00:02:27 -0600
committerJeff Carr <[email protected]>2024-11-28 00:02:27 -0600
commit0401b949c6f900891f1eefaba41295d2c2a96b07 (patch)
treeb95a0a23fe444e212ab873f90b2f347303785b56 /init.go
parent54a93cd5ebbaf7ed72704c1af9a8be5b8c71f5bd (diff)
added Init() and a Forge struct
Diffstat (limited to 'init.go')
-rw-r--r--init.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/init.go b/init.go
new file mode 100644
index 0000000..8c6af82
--- /dev/null
+++ b/init.go
@@ -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()
+}