From 3adf07b442c62bd70e7bf37d4c07e51464b25e09 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 21 Nov 2024 10:37:01 -0600 Subject: hmmm Signed-off-by: Jeff Carr --- forgeConfig/main.go | 3 +- human.go | 14 +++++++++ readonly.go | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ update.go | 91 ----------------------------------------------------- 4 files changed, 106 insertions(+), 93 deletions(-) create mode 100644 readonly.go delete mode 100644 update.go diff --git a/forgeConfig/main.go b/forgeConfig/main.go index cd07016..e874304 100644 --- a/forgeConfig/main.go +++ b/forgeConfig/main.go @@ -11,8 +11,7 @@ import ( var VERSION string func main() { - var repos *forgepb.Repos - repos = new(forgepb.Repos) + var repos forgepb.Repos if err := repos.ConfigLoad(); err != nil { log.Warn("forgepb.ConfigLoad() failed", err) os.Exit(-1) diff --git a/human.go b/human.go index 479c6d6..322e6c2 100644 --- a/human.go +++ b/human.go @@ -1,5 +1,7 @@ package forgepb +import "fmt" + // mostly just functions related to making STDOUT // more readable by us humans @@ -10,3 +12,15 @@ package forgepb func RepoHeader() string { return "Name Path" } + +func (all *Repos) StandardHeader() string { + return fmt.Sprintf("%-4s %40s %s", "r/w", "Path", "flags") +} + +func (r *Repo) StandardHeader() string { + var flags string + if r.Private { + flags += "(private) " + } + return fmt.Sprintf("%-4s %40s %s", "true", r.GoPath, flags) +} diff --git a/readonly.go b/readonly.go new file mode 100644 index 0000000..27e23ee --- /dev/null +++ b/readonly.go @@ -0,0 +1,91 @@ +package forgepb + +import "strings" + +func (all *Repos) UpdateGoPath(name string, gopath string) bool { + oldr := all.DeleteByPath(name) + if oldr == nil { + // nothing to update + return false + } + + // update gopath and append it back to the list + oldr.GoPath = gopath + return all.Append(oldr) +} + +// returns true if gopath is readonly() +func (all *Repos) IsReadOnly(gopath string) bool { + var match *Repo + + loop := all.SortByPath() // get the list of repos + for loop.Scan() { + r := loop.Repo() + if r.GoPath == gopath { + // exact gopath match + if r.Writable { + return false + } + if r.ReadOnly { + return true + } + // private is assumed to be r/w unless above is specifically set + if r.Private { + return false + } + } + // search for potential dir matches + if r.Directory { + // test the dir + if strings.HasPrefix(gopath, r.GoPath) { + match = r + } + } + } + + // take the settings from the directory match + if match.Writable { + return false + } + if match.ReadOnly { + return true + } + // private is assumed to be r/w unless above is specifically set + if match.Private { + return false + } + + // always assume readonly + return true +} + +// is this a non-publishable repo? +func (all *Repos) IsPrivate(gopath string) bool { + var match *Repo + + loop := all.SortByPath() // get the list of repos + for loop.Scan() { + r := loop.Repo() + if r.GoPath == gopath { + // if private is set here, then ok, otherwise + // still check if a Directory match exists + if r.Private { + return true + } + } + // search for potential dir matches + if r.Directory { + // test the dir + if strings.HasPrefix(gopath, r.GoPath) { + match = r + } + } + } + + if match.Private { + return true + } + + // otherwise, assume not private + return true +} diff --git a/update.go b/update.go deleted file mode 100644 index 27e23ee..0000000 --- a/update.go +++ /dev/null @@ -1,91 +0,0 @@ -package forgepb - -import "strings" - -func (all *Repos) UpdateGoPath(name string, gopath string) bool { - oldr := all.DeleteByPath(name) - if oldr == nil { - // nothing to update - return false - } - - // update gopath and append it back to the list - oldr.GoPath = gopath - return all.Append(oldr) -} - -// returns true if gopath is readonly() -func (all *Repos) IsReadOnly(gopath string) bool { - var match *Repo - - loop := all.SortByPath() // get the list of repos - for loop.Scan() { - r := loop.Repo() - if r.GoPath == gopath { - // exact gopath match - if r.Writable { - return false - } - if r.ReadOnly { - return true - } - // private is assumed to be r/w unless above is specifically set - if r.Private { - return false - } - } - // search for potential dir matches - if r.Directory { - // test the dir - if strings.HasPrefix(gopath, r.GoPath) { - match = r - } - } - } - - // take the settings from the directory match - if match.Writable { - return false - } - if match.ReadOnly { - return true - } - // private is assumed to be r/w unless above is specifically set - if match.Private { - return false - } - - // always assume readonly - return true -} - -// is this a non-publishable repo? -func (all *Repos) IsPrivate(gopath string) bool { - var match *Repo - - loop := all.SortByPath() // get the list of repos - for loop.Scan() { - r := loop.Repo() - if r.GoPath == gopath { - // if private is set here, then ok, otherwise - // still check if a Directory match exists - if r.Private { - return true - } - } - // search for potential dir matches - if r.Directory { - // test the dir - if strings.HasPrefix(gopath, r.GoPath) { - match = r - } - } - } - - if match.Private { - return true - } - - // otherwise, assume not private - return true -} -- cgit v1.2.3