summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-08-18 06:10:58 -0500
committerJeff Carr <[email protected]>2025-08-18 06:10:58 -0500
commit554adc9f0ff5e6cbeb0de1dc4f3fdf98ddddfe52 (patch)
treedc6478955f559e7229c0e5a8ade804d6a16c39d7
parent25cee2b0134413d8501dc808a866a921bf995a7d (diff)
experiement with ~/.cache/forge/
-rw-r--r--goSrcScan.go9
-rw-r--r--init.go49
2 files changed, 55 insertions, 3 deletions
diff --git a/goSrcScan.go b/goSrcScan.go
index 86e4341..5555ac5 100644
--- a/goSrcScan.go
+++ b/goSrcScan.go
@@ -46,10 +46,13 @@ func (f *Forge) ScanGoSrc() (bool, error) {
return true, err
}
+// returns a repo protobuf for a directory if the directory is a git repo
func (f *Forge) ScanDir(dir string) *gitpb.Repo {
- // repo, err := f.NewGoRepo(gopath, "")
- repo, err := f.Repos.NewGoRepo(dir, "")
- log.Info("need to implement ScanDir()", dir, err)
+ repo, err := f.Repos.NewRepo(dir, "")
+ if err != nil {
+ log.Info("ScanDir() error", dir, err)
+ return nil
+ }
return repo
}
diff --git a/init.go b/init.go
index 57e18fd..72100df 100644
--- a/init.go
+++ b/init.go
@@ -180,3 +180,52 @@ func (f *Forge) Exit() {
// log.Info("forge.Exit() ok")
os.Exit(0)
}
+
+func RawInitPB() *Forge {
+ f := new(Forge)
+
+ homeDir, _ := os.UserHomeDir()
+ // todo: check or exit if err?
+
+ // TODO: rethink this but it works for now
+ if os.Getenv("FORGE_GOSRC") == "" {
+ fullpath := filepath.Join(homeDir, ".cache/forge")
+ err := os.MkdirAll(fullpath, os.ModePerm)
+ if err != nil {
+ log.Log(WARN, "mkdir failed", fullpath, err)
+ }
+ os.Setenv("FORGE_GOSRC", fullpath)
+ }
+ f.goSrc = os.Getenv("FORGE_GOSRC")
+
+ // also rethink this, but maybe this is the right thing to do
+ if os.Getenv("FORGE_CONFIG") == "" {
+ fullpath := filepath.Join(homeDir, ".config/forge")
+ os.MkdirAll(fullpath, os.ModePerm)
+ os.Setenv("FORGE_CONFIG", fullpath)
+ }
+
+ f.configDir = os.Getenv("FORGE_CONFIG")
+
+ // load the ~/.config/forge/ config
+ f.Config = new(ForgeConfigs)
+ if err := f.Config.ConfigLoad(); err != nil {
+ log.Log(WARN, "forgepb.ConfigLoad() failed", err)
+ }
+
+ f.Repos = gitpb.NewRepos()
+ f.Repos.ConfigLoad()
+
+ f.forgeURL = "https://forge.wit.com/"
+
+ if os.Getenv("FORGE_URL") != "" {
+ f.forgeURL = os.Getenv("FORGE_URL")
+ log.Info("got forge url", f.forgeURL)
+ }
+
+ // todo: play with these / determine good values based on user's machine
+ f.rillX = 10
+ f.rillY = 20
+
+ return f
+}