start making this tool useful

This commit is contained in:
Jeff Carr 2024-12-03 00:33:17 -06:00
parent 10193b77f2
commit 659bed891b
6 changed files with 88 additions and 60 deletions

View File

@ -42,11 +42,19 @@ list: build
list-real: build list-real: build
reset reset
./forge --list --real ./forge --list --fix
list-readonly: build
reset
./forge --list --readonly
list-config: build list-config: build
./forge --list-conf ./forge --list-conf
scan: build
reset
./forge --scan
mine: build mine: build
./forge --mine ./forge --mine

View File

@ -9,7 +9,8 @@ var argv args
type args struct { type args struct {
List bool `arg:"--list" help:"list found repos"` List bool `arg:"--list" help:"list found repos"`
ListConf bool `arg:"--list-conf" help:"list your .config/forge/ configuration"` ListConf bool `arg:"--list-conf" help:"list your .config/forge/ configuration"`
ReadOnly bool `arg:"--read-only" help:"include read-only repos"` Scan bool `arg:"--scan" help:"rescan your repos"`
ReadOnly bool `arg:"--readonly" help:"include read-only repos"`
GetMine bool `arg:"--mine" help:"download private and writeable repos"` GetMine bool `arg:"--mine" help:"download private and writeable repos"`
GetFav bool `arg:"--favorites" help:"download repos marked as favorites"` GetFav bool `arg:"--favorites" help:"download repos marked as favorites"`
Pull bool `arg:"--git-pull" help:"run 'git pull' on all your repos"` Pull bool `arg:"--git-pull" help:"run 'git pull' on all your repos"`
@ -17,7 +18,7 @@ type args struct {
Install bool `arg:"--install" help:"try to install every binary package"` Install bool `arg:"--install" help:"try to install every binary package"`
RedoGoMod bool `arg:"--RedoGoMod" help:"remake all the go.sum and go.mod files"` RedoGoMod bool `arg:"--RedoGoMod" help:"remake all the go.sum and go.mod files"`
DryRun bool `arg:"--dry-run" help:"show what would be run"` DryRun bool `arg:"--dry-run" help:"show what would be run"`
Real bool `arg:"--real" help:"do the change, save config & exit"` Real bool `arg:"--fix" help:"fix config, save config & exit"`
} }
func (args) Version() string { func (args) Version() string {

41
delete.go Normal file
View File

@ -0,0 +1,41 @@
package main
import (
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
func Delete(repo *gitpb.Repo, s map[string]string) bool {
if repo.Published == nil {
log.Info("published is nil", repo.Published)
} else {
log.Info("published len", repo.Published.Len())
}
// add a new one here
newr := gitpb.Repo{
FullPath: repo.FullPath,
GoPath: repo.GoPath,
URL: repo.URL,
Tags: repo.Tags,
LastPull: repo.LastPull,
MasterBranchName: repo.MasterBranchName,
DevelBranchName: repo.DevelBranchName,
UserBranchName: repo.UserBranchName,
GoLibrary: repo.GoLibrary,
GoBinary: repo.GoBinary,
GoPrimitive: repo.GoPrimitive,
GoPlugin: repo.GoPlugin,
GoDeps: repo.GoDeps,
LastGoDep: repo.LastGoDep,
Dirty: repo.Dirty,
Published: repo.Published,
TargetVersion: repo.TargetVersion,
ReadOnly: repo.ReadOnly,
GoProtobuf: repo.GoProtobuf,
}
if argv.Real {
me.forge.Repos.AppendUniqueGoPath(&newr)
}
return true
}

81
list.go
View File

@ -9,6 +9,7 @@ import (
) )
func list() { func list() {
log.DaemonMode(true)
if argv.ListConf { if argv.ListConf {
me.forge.ConfigPrintTable() me.forge.ConfigPrintTable()
os.Exit(0) os.Exit(0)
@ -18,24 +19,7 @@ func list() {
repos := me.forge.Repos.SortByGoPath() repos := me.forge.Repos.SortByGoPath()
for repos.Scan() { for repos.Scan() {
repo := repos.Next() repo := repos.Next()
var end string verifyPrint(repo)
if repo.CheckDirty() {
end += "(dirty) "
}
s := make(map[string]string)
if !verify(repo, s) {
log.Info("going to delete", repo.GoPath)
if argv.Real {
me.forge.Repos.DeleteByGoPath(repo.GetGoPath())
me.forge.Repos.ConfigSave()
} else {
log.Info("need argv --real to delete", repo.GoPath)
}
os.Exit(0)
}
start := fmt.Sprintf("%-50s %-8s %-10s %-10s %-10s %-10s", s["gopath"], s["rtype"], s["mver"], s["dver"], s["uver"], s["cver"])
end += fmt.Sprintf("(%s,%s,%s,%s) ", s["mname"], s["dname"], s["uname"], s["cname"])
log.Info(start, end)
} }
os.Exit(0) os.Exit(0)
} }
@ -51,51 +35,32 @@ func list() {
} }
} }
func whichOne(repo *gitpb.Repo, a map[string]any, hmm string) any { func verifyPrint(repo *gitpb.Repo) {
return nil var end string
} if repo.CheckDirty() {
end += "(dirty) "
func updateRepo(repo *gitpb.Repo, a map[string]any) bool {
return false
}
func Delete(repo *gitpb.Repo, s map[string]string) bool {
if repo.Published == nil {
log.Info("published is nil", repo.Published)
} else {
log.Info("published len", repo.Published.Len())
} }
s := make(map[string]string)
// add a new one here if !verify(repo, s) {
newr := gitpb.Repo{ log.Info("going to delete", repo.GoPath)
FullPath: repo.FullPath, if argv.Real {
GoPath: repo.GoPath, me.forge.Repos.DeleteByGoPath(repo.GetGoPath())
URL: repo.URL, me.forge.Repos.ConfigSave()
Tags: repo.Tags, } else {
LastPull: repo.LastPull, log.Info("need argv --real to delete", repo.GoPath)
MasterBranchName: repo.MasterBranchName, }
DevelBranchName: repo.DevelBranchName, os.Exit(0)
UserBranchName: repo.UserBranchName,
GoLibrary: repo.GoLibrary,
GoBinary: repo.GoBinary,
GoPrimitive: repo.GoPrimitive,
GoPlugin: repo.GoPlugin,
GoDeps: repo.GoDeps,
LastGoDep: repo.LastGoDep,
Dirty: repo.Dirty,
Published: repo.Published,
TargetVersion: repo.TargetVersion,
ReadOnly: repo.ReadOnly,
GoProtobuf: repo.GoProtobuf,
} }
if argv.Real { if me.forge.IsReadOnly(repo.GoPath) && ! argv.ReadOnly {
me.forge.Repos.AppendUniqueGoPath(&newr) return
} }
return true start := fmt.Sprintf("%-40s %-8s %-10s %-10s %-10s %-10s", s["gopath"], s["rtype"], s["mver"], s["dver"], s["uver"], s["cver"])
end += fmt.Sprintf("(%s,%s,%s,%s) ", s["mname"], s["dname"], s["uname"], s["cname"])
log.Info(start, end)
} }
func verify(repo *gitpb.Repo, s map[string]string) bool { func verify(repo *gitpb.Repo, s map[string]string) bool {
if ! repo.IsValid() { if !repo.IsValid() {
return false return false
} }
s["gopath"] = repo.GetGoPath() s["gopath"] = repo.GetGoPath()
@ -104,10 +69,12 @@ func verify(repo *gitpb.Repo, s map[string]string) bool {
s["mname"] = repo.GetMasterBranchName() s["mname"] = repo.GetMasterBranchName()
if s["mname"] == "" { if s["mname"] == "" {
log.Info("verify() no master branch name") log.Info("verify() no master branch name")
s["mver"] = repo.GetMasterVersion()
return false return false
} }
// only verify the master branch name with read-only repos // only verify the master branch name with read-only repos
if me.forge.IsReadOnly(repo.GoPath) { if me.forge.IsReadOnly(repo.GoPath) {
s["mver"] = repo.GetMasterVersion()
return true return true
} }

View File

@ -28,6 +28,8 @@ func main() {
// processes any --list like options // processes any --list like options
// may exit // may exit
list() list()
scan()
os.Exit(0)
if argv.RedoGoMod { if argv.RedoGoMod {
repos := me.forge.Repos.SortByGoPath() repos := me.forge.Repos.SortByGoPath()

9
scan.go Normal file
View File

@ -0,0 +1,9 @@
package main
func scan() {
if !argv.Scan {
return
}
me.forge.ScanGoSrc()
list()
}