This commit is contained in:
Jeff Carr 2024-11-25 00:46:16 -06:00
parent 84d04f28c9
commit e924aa4b7d
3 changed files with 58 additions and 21 deletions

View File

@ -16,13 +16,17 @@ func main() {
log.Warn("forgepb.ConfigLoad() failed", err)
os.Exit(-1)
}
if argv.List {
repos.PrintTable()
/*
log.Info(forgepb.RepoHeader())
loop := repos.SortByPath() // get the list of repos
for loop.Scan() {
r := loop.Repo()
log.Info("repo:", r.GoPath)
}
*/
os.Exit(0)
}

View File

@ -14,12 +14,8 @@ import (
// so reporting tables of the status of what droplets and hypervisors
// are in text columns and rows that can be easily read in a terminal
func RepoHeader() string {
return "Name Path"
}
func standardHeader() string {
return fmt.Sprintf("%-4s %40s %s", "r/w", "Path", "flags")
return fmt.Sprintf("%-4s %-40s %s", "", "Path", "flags")
}
func (all *Repos) standardHeader(r *Repo) string {
@ -28,6 +24,9 @@ func (all *Repos) standardHeader(r *Repo) string {
if all.IsPrivate(r.GoPath) {
flags += "(private) "
}
if all.IsFavorite(r.GoPath) {
flags += "(favorite) "
}
if all.IsReadOnly(r.GoPath) {
readonly = ""
} else {

View File

@ -84,6 +84,30 @@ func (all *Repos) IsReadOnly(gopath string) bool {
return true
}
// returns the deb package name
// this let's you check a git tag version against a package .deb version
// allows gopath's to not need to match the .deb name
// this is important in lots of cases! It is normal and happens often enough.
func (all *Repos) DebName(gopath string) string {
// get "zookeeper" from "go.wit.com/apps/zookeeper"
normalBase := filepath.Base(gopath)
loop := all.SortByPath()
for loop.Scan() {
r := loop.Repo()
if r.GoPath == gopath {
// returns "zookeeper-go" for "go.wit.com/apps/zookeeper"
if r.DebName != "" {
// log.Info("FOUND DebName", r.DebName)
return r.DebName
} else {
return normalBase
}
}
}
return normalBase
}
// is this a non-publishable repo?
// matches package names from apt
//
@ -131,26 +155,36 @@ func (all *Repos) IsPrivate(thing string) bool {
return match.Private
}
// returns the deb package name
// this let's you check a git tag version against a package .deb version
// allows gopath's to not need to match the .deb name
// this is important in lots of cases! It is normal and happens often enough.
func (all *Repos) DebName(gopath string) string {
// get "zookeeper" from "go.wit.com/apps/zookeeper"
normalBase := filepath.Base(gopath)
// IsFavorite() -- fun option for the config
// file that lets you set things as favorites
// so you can just go-clone a bunch of common things
// on a new box or after you reset/delete your ~/go/src dir
func (all *Repos) IsFavorite(thing string) bool {
var match *Repo
loop := all.SortByPath()
loop := all.SortByPath() // get the list of repos
for loop.Scan() {
r := loop.Repo()
if r.GoPath == gopath {
// returns "zookeeper-go" for "go.wit.com/apps/zookeeper"
if r.DebName != "" {
// log.Info("FOUND DebName", r.DebName)
return r.DebName
} else {
return normalBase
if r.GoPath == thing {
if r.Favorite {
return true
}
}
base := filepath.Base(r.GoPath)
if base == thing {
if r.Favorite {
return true
}
}
if r.Directory {
if strings.HasPrefix(thing, r.GoPath) {
match = r
}
}
}
return normalBase
if match == nil {
return false
}
return match.Favorite
}