From ee82f38e4df6a209dac806e08116e748f9a9e953 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 21 Oct 2025 06:41:44 -0500 Subject: use lib/ENV --- clone.go | 4 ++-- config.go | 10 +++++----- init.go | 35 ++++++++++++++++++----------------- repoNew.go | 11 ++++++----- rill.go | 17 +++++++++-------- scanRepoDir.go | 7 ++++--- 6 files changed, 44 insertions(+), 40 deletions(-) diff --git a/clone.go b/clone.go index be5a662..d44874e 100644 --- a/clone.go +++ b/clone.go @@ -10,13 +10,13 @@ import ( "path/filepath" "strings" - "go.wit.com/lib/config" + "go.wit.com/lib/ENV" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) func getClonePathFromMode() string { - return config.Get("gopath") + return ENV.Get("gopath") } // will not violate filesystem namespace diff --git a/config.go b/config.go index b51b99f..5c8f2a3 100644 --- a/config.go +++ b/config.go @@ -6,6 +6,7 @@ import ( "errors" "os" + "go.wit.com/lib/ENV" "go.wit.com/lib/config" "go.wit.com/lib/protobuf/argvpb" "go.wit.com/log" @@ -61,11 +62,11 @@ func (f *Forge) SetMode(newmode ForgeMode) error { return nil } f.mode = newmode - err := config.Set("mode", newmode.String()) + err := ENV.Set("mode", newmode.String()) if err != nil { panic("config.Set() doesn't work") } - err = config.Save() + err = ENV.Save() if err != nil { panic("config.Save() doesn't work") } @@ -102,8 +103,8 @@ func (f *Forge) DumpENV() { } func DumpENV() { - log.Infof("forge ReposDir = %s\n", config.Get("ReposDir")) - log.Infof("forge ForgeURL = %s\n", config.Get("ForgeURL")) + log.Infof("forge ReposDir = %s\n", ENV.Get("ReposDir")) + log.Infof("forge ForgeURL = %s\n", ENV.Get("ForgeURL")) } func loadStdConfig() (*ForgeConfigs, error) { @@ -134,7 +135,6 @@ func makeDefaultConfig() (*ForgeConfigs, error) { cfg.addSampleConfigs() DumpENV() - config.SetChanged("forge", true) var err error if err = cfg.SaveVerbose(); err != nil { log.Info("config save error:", err) diff --git a/init.go b/init.go index 695319d..bdf0469 100644 --- a/init.go +++ b/init.go @@ -7,6 +7,7 @@ import ( "os/user" "path/filepath" + "go.wit.com/lib/ENV" "go.wit.com/lib/cobol" "go.wit.com/lib/config" "go.wit.com/lib/protobuf/gitpb" @@ -56,28 +57,28 @@ func initFromConfig(cfg *ForgeConfigs) *Forge { f.Config.loadConfig() // always define - if config.Get("username") == "" { + if ENV.Get("username") == "" { usr, _ := user.Current() - config.Set("username", usr.Username) - config.Save() + ENV.Set("username", usr.Username) + ENV.Save() } // always define - if config.Get("homeDir") == "" { + if ENV.Get("homeDir") == "" { homeDir, _ := os.UserHomeDir() - config.Set("homeDir", homeDir) - config.Save() + ENV.Set("homeDir", homeDir) + ENV.Save() } // always define - if config.Get("gopath") == "" { - gopath := filepath.Join(config.Get("homedir"), "go/src") - config.Set("gopath", gopath) - config.Save() + if ENV.Get("gopath") == "" { + gopath := filepath.Join(ENV.Get("homedir"), "go/src") + ENV.Set("gopath", gopath) + ENV.Save() } // always set f.mode - switch config.Get("Mode") { + switch ENV.Get("Mode") { case "NORMAL": f.mode = ForgeMode_NORMAL case "CLEAN": @@ -89,13 +90,13 @@ func initFromConfig(cfg *ForgeConfigs) *Forge { } // todo: play with these / determine good values based on user's machine - if cobol.Int(config.Get("RillX")) == 0 { - config.Set("RillX", "10") - config.Save() + if cobol.Int(ENV.Get("RillX")) == 0 { + ENV.Set("RillX", "10") + ENV.Save() } - if cobol.Int(config.Get("RillY")) == 0 { - config.Set("RillY", "20") - config.Save() + if cobol.Int(ENV.Get("RillY")) == 0 { + ENV.Set("RillY", "20") + ENV.Save() } // create an initial repos.pb file diff --git a/repoNew.go b/repoNew.go index 677f3ca..fe7da04 100644 --- a/repoNew.go +++ b/repoNew.go @@ -9,13 +9,14 @@ import ( "regexp" "strings" + "go.wit.com/lib/ENV" "go.wit.com/lib/config" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) func (f *Forge) NewGoRepo(gopath string, url string) (*gitpb.Repo, error) { - fullpath := filepath.Join(config.Get("ReposDir"), gopath) + fullpath := filepath.Join(ENV.Get("ReposDir"), gopath) test := f.Repos.FindByFullPath(fullpath) if test != nil { return test, nil @@ -192,12 +193,12 @@ func (f *Forge) configUserBranchName(repo *gitpb.Repo) string { if uname != "" { return uname } - if config.Get("username") == "" { + if ENV.Get("username") == "" { // something is wrong! } // use the os.Username - uname = config.Get("username") + uname = ENV.Get("username") return uname } @@ -230,7 +231,7 @@ func (f *Forge) AddFullPath(fulldir string) *gitpb.Repo { // } func (f *Forge) FindByNamespace(gopath string) *gitpb.Repo { - fullpath := filepath.Join(config.Get("ReposDir"), gopath) + fullpath := filepath.Join(ENV.Get("ReposDir"), gopath) return f.Repos.FindByFullPath(fullpath) } @@ -257,6 +258,6 @@ func (f *Forge) FindAnyPath(dir string) *gitpb.Repo { } func (f *Forge) DeleteByGoPath(gopath string) bool { - fullpath := filepath.Join(config.Get("ReposDir"), gopath) + fullpath := filepath.Join(ENV.Get("ReposDir"), gopath) return f.Repos.DeleteByFullPath(fullpath) } diff --git a/rill.go b/rill.go index 013c79f..de01b00 100644 --- a/rill.go +++ b/rill.go @@ -6,6 +6,7 @@ import ( "time" "github.com/destel/rill" + "go.wit.com/lib/ENV" "go.wit.com/lib/cobol" "go.wit.com/lib/config" "go.wit.com/lib/protobuf/gitpb" @@ -36,11 +37,11 @@ func (f *Forge) RillReload() int { var counter int // Read users from the API. // Concurrency = 20 - dirs := rill.Map(ids, cobol.Int(config.Get("RillX")), func(repo *gitpb.Repo) (*gitpb.Repo, error) { + dirs := rill.Map(ids, cobol.Int(ENV.Get("RillX")), func(repo *gitpb.Repo) (*gitpb.Repo, error) { return repo, nil }) - rill.ForEach(dirs, cobol.Int(config.Get("RillY")), func(repo *gitpb.Repo) error { + rill.ForEach(dirs, cobol.Int(ENV.Get("RillY")), func(repo *gitpb.Repo) error { if err := repo.HasChanged(); err != nil { counter += 1 return err @@ -60,8 +61,8 @@ func (f *Forge) RillFuncError(rillf func(*gitpb.Repo) error) map[string]*RillSta } func (f *Forge) ConfigRill(rillX int, rillY int) { - config.Set("RillX", fmt.Sprintf("%d", rillX)) - config.Set("RillY", fmt.Sprintf("%d", rillY)) + ENV.Set("RillX", fmt.Sprintf("%d", rillX)) + ENV.Set("RillY", fmt.Sprintf("%d", rillY)) // log.Infof("Setting rill values to %d,%d\n", f.Config.RillX, f.Config.RillY) } @@ -136,11 +137,11 @@ func (f *Forge) RillRepos(rillf func(*gitpb.Repo) error) map[string]*RillStats { // Read users from the API. // Concurrency = 20 - dirs := rill.Map(ids, cobol.Int(config.Get("RillX")), func(id *gitpb.Repo) (*gitpb.Repo, error) { + dirs := rill.Map(ids, cobol.Int(ENV.Get("RillX")), func(id *gitpb.Repo) (*gitpb.Repo, error) { return id, nil }) - rill.ForEach(dirs, cobol.Int(config.Get("RillY")), func(repo *gitpb.Repo) error { + rill.ForEach(dirs, cobol.Int(ENV.Get("RillY")), func(repo *gitpb.Repo) error { // todo: make this a goroutine to show stats to the user rillMu.Lock() counter += 1 @@ -187,11 +188,11 @@ func (f *Forge) RunOnRepos(repos *gitpb.Repos, rillf func(*gitpb.Repo) error) ma // Read users from the API. // Concurrency = 20 - dirs := rill.Map(ids, cobol.Int(config.Get("RillX")), func(id *gitpb.Repo) (*gitpb.Repo, error) { + dirs := rill.Map(ids, cobol.Int(ENV.Get("RillX")), func(id *gitpb.Repo) (*gitpb.Repo, error) { return id, nil }) - rill.ForEach(dirs, cobol.Int(config.Get("RillY")), func(repo *gitpb.Repo) error { + rill.ForEach(dirs, cobol.Int(ENV.Get("RillY")), func(repo *gitpb.Repo) error { // todo: make this a goroutine to show stats to the user rillMu.Lock() counter += 1 diff --git a/scanRepoDir.go b/scanRepoDir.go index 4d8cc2f..21e411d 100644 --- a/scanRepoDir.go +++ b/scanRepoDir.go @@ -7,6 +7,7 @@ import ( "path/filepath" "github.com/destel/rill" + "go.wit.com/lib/ENV" "go.wit.com/lib/cobol" "go.wit.com/lib/config" "go.wit.com/lib/protobuf/gitpb" @@ -38,7 +39,7 @@ func (f *Forge) checkNamespace(fullpath string) (*gitpb.Repo, error) { } func (f *Forge) RescanRepos() error { - gopath := config.Get("gopath") + gopath := ENV.Get("gopath") log.Info("RescanRepos() running in", gopath) f.ScanRepoDir(gopath) // f.SaveRepos() @@ -83,13 +84,13 @@ func (f *Forge) rillScanDirsNew(fullpaths []string) (int, error) { ids := rill.FromSlice(fullpaths, nil) // Read users from the API. // Concurrency = 20 - dirs := rill.Map(ids, cobol.Int(config.Get("RillX")), func(id string) (*gitpb.Repo, error) { + dirs := rill.Map(ids, cobol.Int(ENV.Get("RillX")), func(id string) (*gitpb.Repo, error) { return f.checkNamespace(id) }) var counter int // Activate users. // Concurrency = 10 - err := rill.ForEach(dirs, cobol.Int(config.Get("RillY")), func(repo *gitpb.Repo) error { + err := rill.ForEach(dirs, cobol.Int(ENV.Get("RillY")), func(repo *gitpb.Repo) error { if repo == nil { return nil } -- cgit v1.2.3