From 38c0ec7caadcfa51baf364b76cda14e2c656d0ee Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 6 Jan 2025 20:57:52 -0600 Subject: move config handling here --- doConfig.go | 28 +++++++++++++++++ find.go | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ findRepos.go | 100 ----------------------------------------------------------- main.go | 31 +++++------------- 4 files changed, 135 insertions(+), 124 deletions(-) create mode 100644 doConfig.go create mode 100644 find.go delete mode 100644 findRepos.go diff --git a/doConfig.go b/doConfig.go new file mode 100644 index 0000000..52581c8 --- /dev/null +++ b/doConfig.go @@ -0,0 +1,28 @@ +package main + +import ( + "go.wit.com/log" +) + +func doConfig() { + if argv.Config.Delete != "" { + me.forge.DeleteByGoPath(argv.Config.Delete) + me.forge.SetConfigSave(true) + okExit("") + } + + if argv.Config.Fix != nil { + log.Info("todo") + okExit("") + } + if argv.Config.Register != "" { + if err := doRegister(argv.Config.Register); err == nil { + okExit("attempting to register " + argv.Config.Register) + } else { + badExit(err) + } + } + + me.forge.ConfigPrintTable() + okExit("") +} diff --git a/find.go b/find.go new file mode 100644 index 0000000..f90d4ee --- /dev/null +++ b/find.go @@ -0,0 +1,100 @@ +package main + +import ( + "go.wit.com/lib/protobuf/gitpb" +) + +// this populates a slice of protobuf records representing each git repo +// var me.found []*gitpb.Repo +// +// so, it makes a subset of repos that are then used performing actions on +// +// by default, it adds every repo + +func (f *FindCmd) findRepos() { + if f == nil { + findMine() + return + } + + if f.All { + findAll() + return + } + + if f.Private { + findPrivate() + return + } + + if f.Mine { + findMine() + return + } + + if f.Favorites { + findFavorites() + return + } + + if f.Dirty { + findDirty() + return + } + + findAll() +} + +func findPrivate() { + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + repo := all.Next() + if me.forge.Config.IsPrivate(repo.GetGoPath()) { + me.found.AppendUniqueGoPath(repo) + } + } +} + +// finds repos that are writable +func findMine() { + // log.Printf("get mine %s\n", me.forge.GetGoSrc()) + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + repo := all.Next() + if me.forge.Config.IsWritable(repo.GetGoPath()) { + me.found.AppendUniqueGoPath(repo) + } + } +} + +// finds repos the user has marked as favorites in the forge .config +func findFavorites() { + // log.Printf("get favorites %s\n", me.forge.GetGoSrc()) + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + repo := all.Next() + if me.forge.Config.IsFavorite(repo.GetGoPath()) { + me.found.AppendUniqueGoPath(repo) + } + } +} + +// finds repos that git is reporting as dirty +func findDirty() { + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + var repo *gitpb.Repo + repo = all.Next() + if repo.IsDirty() { + me.found.AppendUniqueGoPath(repo) + } + } +} + +func findAll() { + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + repo := all.Next() + me.found.AppendUniqueGoPath(repo) + } +} diff --git a/findRepos.go b/findRepos.go deleted file mode 100644 index f90d4ee..0000000 --- a/findRepos.go +++ /dev/null @@ -1,100 +0,0 @@ -package main - -import ( - "go.wit.com/lib/protobuf/gitpb" -) - -// this populates a slice of protobuf records representing each git repo -// var me.found []*gitpb.Repo -// -// so, it makes a subset of repos that are then used performing actions on -// -// by default, it adds every repo - -func (f *FindCmd) findRepos() { - if f == nil { - findMine() - return - } - - if f.All { - findAll() - return - } - - if f.Private { - findPrivate() - return - } - - if f.Mine { - findMine() - return - } - - if f.Favorites { - findFavorites() - return - } - - if f.Dirty { - findDirty() - return - } - - findAll() -} - -func findPrivate() { - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - if me.forge.Config.IsPrivate(repo.GetGoPath()) { - me.found.AppendUniqueGoPath(repo) - } - } -} - -// finds repos that are writable -func findMine() { - // log.Printf("get mine %s\n", me.forge.GetGoSrc()) - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - if me.forge.Config.IsWritable(repo.GetGoPath()) { - me.found.AppendUniqueGoPath(repo) - } - } -} - -// finds repos the user has marked as favorites in the forge .config -func findFavorites() { - // log.Printf("get favorites %s\n", me.forge.GetGoSrc()) - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - if me.forge.Config.IsFavorite(repo.GetGoPath()) { - me.found.AppendUniqueGoPath(repo) - } - } -} - -// finds repos that git is reporting as dirty -func findDirty() { - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - var repo *gitpb.Repo - repo = all.Next() - if repo.IsDirty() { - me.found.AppendUniqueGoPath(repo) - } - } -} - -func findAll() { - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - me.found.AppendUniqueGoPath(repo) - } -} diff --git a/main.go b/main.go index d8e0ef0..d168b30 100644 --- a/main.go +++ b/main.go @@ -51,6 +51,12 @@ func main() { me.forge = forgepb.Init() me.found = new(gitpb.Repos) + // first find the repos or gopaths to operate on + if argv.Config != nil { + doConfig() + okExit("") + } + if argv.Checkout != nil { if argv.Checkout.User != nil { me.forge.CheckoutUser() @@ -81,30 +87,6 @@ func main() { okExit("") } - // first find the repos or gopaths to operate on - if argv.Config != nil { - if argv.Config.Delete != "" { - me.forge.DeleteByGoPath(argv.Config.Delete) - me.forge.SetConfigSave(true) - okExit("") - } - - if argv.Config.Fix != nil { - log.Info("todo") - okExit("") - } - if argv.Config.Register != "" { - if err := doRegister(argv.Config.Register); err == nil { - okExit("attempting to register " + argv.Config.Register) - } else { - badExit(err) - } - } - - me.forge.ConfigPrintTable() - okExit("") - } - log.Info("found", me.found.Len(), "repos. found", len(me.foundPaths), "paths from .config/forge") if argv.Dirty != nil { @@ -152,6 +134,7 @@ func main() { } } + // todo: redo this logic using forgepb if configSave { me.forge.ConfigSave() configSave = false -- cgit v1.2.3