summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-05 12:37:24 -0600
committerJeff Carr <[email protected]>2024-12-05 12:37:24 -0600
commit205e6f022befe1cee748765c71e688b532e03fcb (patch)
treea6be705b97fdfdde6fabd2c6401e8f0ff56733ef
parent77cd0ae36e79748b56e9bf0964fee677631f9fd0 (diff)
making config files more viablev0.0.25v0.0.24
-rw-r--r--config.go32
-rw-r--r--rill.go4
2 files changed, 25 insertions, 11 deletions
diff --git a/config.go b/config.go
index e88a4a2..99ba64d 100644
--- a/config.go
+++ b/config.go
@@ -11,12 +11,12 @@ import (
"go.wit.com/log"
)
-// write to ~/.config/forge/ unless ENV{FORGE_HOME} is set
+// write to ~/.config/forge/ unless ENV{FORGE_CONFIG} is set
func (all *Repos) ConfigSave() error {
- if os.Getenv("FORGE_HOME") == "" {
+ if os.Getenv("FORGE_CONFIG") == "" {
homeDir, _ := os.UserHomeDir()
fullpath := filepath.Join(homeDir, ".config/forge")
- os.Setenv("FORGE_HOME", fullpath)
+ os.Setenv("FORGE_CONFIG", fullpath)
}
if all == nil {
log.Warn("gitpb all == nil")
@@ -35,10 +35,10 @@ func (all *Repos) ConfigSave() error {
// load the ~/.config/forge/ files
func (all *Repos) ConfigLoad() error {
- if os.Getenv("FORGE_HOME") == "" {
+ if os.Getenv("FORGE_CONFIG") == "" {
homeDir, _ := os.UserHomeDir()
fullpath := filepath.Join(homeDir, ".config/forge")
- os.Setenv("FORGE_HOME", fullpath)
+ os.Setenv("FORGE_CONFIG", fullpath)
}
var data []byte
var err error
@@ -52,19 +52,33 @@ func (all *Repos) ConfigLoad() error {
if len(data) == 0 {
// todo: error out if the file is empty?
// try forge.text & forge.json?
+ log.Warn("gitpb.ConfigLoad() repos.pb is empty")
+ return errors.New("gitpb.ConfigLoad() repos.pb is empty")
+ }
+ if all.Repos == nil {
+ log.Warn("gitpb.ConfigLoad() all.Repos == nil")
+ } else {
+ log.Warn("gitpb.ConfigLoad() all.Repos.Len()", all.Len())
}
if err = all.Unmarshal(data); err != nil {
- log.Warn("broken forge.pb config file")
+ log.Warn("gitpb.ConfigLoad() failed", err)
+ if all.Repos == nil {
+ log.Warn("gitpb.ConfigLoad() all.Repos == nil")
+ } else {
+ log.Warn("gitpb.ConfigLoad() all.Repos.Len()", all.Len())
+ log.Warn("gitpb.ConfigLoad() trying to resave the file")
+ all.ConfigSave()
+ }
return err
}
- log.Info("found", len(all.Repos), "repos in ~/.config/forge/repos.pb")
+ log.Info("gitpb.Init()", len(all.Repos), "repos in ~/.config/forge/repos.pb")
return nil
}
return nil
}
func loadFile(filename string) ([]byte, error) {
- fullname := filepath.Join(os.Getenv("FORGE_HOME"), filename)
+ fullname := filepath.Join(os.Getenv("FORGE_CONFIG"), filename)
data, err := os.ReadFile(fullname)
if errors.Is(err, os.ErrNotExist) {
// if file does not exist, just return nil. this
@@ -80,7 +94,7 @@ func loadFile(filename string) ([]byte, error) {
}
func configWrite(filename string, data []byte) error {
- fullname := filepath.Join(os.Getenv("FORGE_HOME"), filename)
+ fullname := filepath.Join(os.Getenv("FORGE_CONFIG"), filename)
cfgfile, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE, 0666)
defer cfgfile.Close()
diff --git a/rill.go b/rill.go
index f1b6b37..facc074 100644
--- a/rill.go
+++ b/rill.go
@@ -36,14 +36,14 @@ func (a GitTagAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
// rill is awesome. long live rill
// attempt scan with rill
-func (all *Repos) rillGitPull() error {
+func (all *Repos) RillGitPull() error {
loop := all.SortByGoPath()
for loop.Scan() {
t := loop.Next()
log.Info("repo", t.GoPath)
}
/*
- packs := all.selectAllRepo()
+ packs := all.SortByGoPath()
// Convert a slice of user IDs into a channel
ids := rill.FromSlice(packs, nil)