developing on this now

This commit is contained in:
Jeff Carr 2024-12-05 12:29:47 -06:00
parent 0463030e80
commit 816760d137
16 changed files with 354 additions and 213 deletions

View File

@ -2,7 +2,7 @@ VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d)
all: goimports vet install
forge -h
forge
vet:
@GO111MODULE=off go vet
@ -33,34 +33,34 @@ redomod:
GO111MODULE= go mod tidy
redomod-all:
forge --RedoGoMod
forge --do-RedoGoMod
redomod-erase:
forge --RedoGoMod --erase
forge --do-RedoGoMod --do-erase
list: install
reset
forge --list
forge --do-list
list-private: install
private: install
reset
forge --list --private
forge --find-private
list-fix: install
reset
forge --list --fix
forge --do-list --do-fix
list-readonly: install
reset
forge --list --readonly
forge --do-list --find-readonly
list-config: install
forge --list-conf
forge --config
scan: install
reset
forge --scan
forge --do-scan
mine: install
forge --mine
forge --find-mine

47
argv.go
View File

@ -7,22 +7,24 @@ package main
var argv args
type args struct {
List bool `arg:"--list" help:"list found repos"`
ListConf bool `arg:"--list-conf" help:"list your .config/forge/ configuration"`
Scan bool `arg:"--scan" help:"rescan your repos"`
ReadOnly bool `arg:"--readonly" help:"include read-only repos"`
Mine bool `arg:"--mine" help:"download private and writeable repos"`
Favorites bool `arg:"--favorites" help:"download repos marked as favorites"`
GitPull bool `arg:"--git-pull" help:"run 'git pull' on all your repos"`
Build bool `arg:"--build" default:"true" help:"also try to build it"`
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"`
DryRun bool `arg:"--dry-run" help:"show what would be run"`
Fix bool `arg:"--fix" help:"fix config, save config & exit"`
Clone bool `arg:"--clone" help:"go-clone things you are missing"`
Force bool `arg:"--force" help:"force redo go-clone"`
Erase bool `arg:"--erase" help:"erase"`
Private bool `arg:"--private" help:"list private repos in .config/forge/"`
Config bool `arg:"--config" help:"work from your .config/forge/ configuration"`
FindAll bool `arg:"--find-all" help:"select every repo"`
FindReadOnly bool `arg:"--find-readonly" help:"include read-only repos"`
FindMine bool `arg:"--find-mine" help:"download private and writeable repos"`
FindFavorites bool `arg:"--find-favorites" help:"download repos marked as favorites"`
FindPrivate bool `arg:"--find-private" help:"list private repos in .config/forge/"`
DoList bool `arg:"--do-list" help:"list found repos"`
DoScan bool `arg:"--do-scan" help:"rescan your repos"`
DoClone bool `arg:"--do-clone" help:"go-clone things you are missing"`
DoForce bool `arg:"--do-force" help:"force redo go-clone"`
DoGitPull bool `arg:"--do-git-pull" help:"run 'git pull' on all your repos"`
DoBuild bool `arg:"--do-build" default:"true" help:"also try to build it"`
DoInstall bool `arg:"--do-install" help:"try to install every binary package"`
DoRedoGoMod bool `arg:"--do-RedoGoMod" help:"remake all the go.sum and go.mod files"`
DoErase bool `arg:"--do-EraseGoMod" help:"erase the go.mod and go.sum files"`
DoGui bool `arg:"--do-gui" help:"test the gui"`
DryRun bool `arg:"--dry-run" help:"show what would be run"`
Fix bool `arg:"--fix" help:"fix config, save config & exit"`
}
func (args) Version() string {
@ -33,14 +35,13 @@ func (a args) Description() string {
return `
forge -- in the spirit of things like sourceforge
Repository configuration is stored in .config/forge/forge.text
Examples:
forge --list # list found repos
forge --mine # download your private and writable repos
forge --favorites # clone repos you marked as favorites
forge --config # shows your forge config (~/.config/forge/)
forge --mine # find your private and writable repos
forge --favorites # find configured as favorites
forge --git-pull # run 'git pull' in every repo
forge --build # build every binary package
forge --install # install every binary package
forge --build --dry-run # build every binary package (but just show what would run)
forge --mine --clone # clone every package you have in your config file
`
}

View File

@ -8,52 +8,67 @@ import (
"go.wit.com/log"
)
func list() {
// ah yes, COBOL. what a throwback. for those that know
// then you know exactly what is in this file. For those that don't, here it is:
// All this does is output human readable text formatted to be viewable on
// a console with a fixed with font. AKA: a typerwriter. Which is exactly
// what COBOL did in the 1970's (60s? notsure) And the 80s.
// So, you want to dump out stuff on the console. Let's see. Something like
/*
forge --favorites
go.wit.com/apps/myapp v0.2.0 (installed)
go.wit.com/lib/somethingfun v0.0.7 (not downloaded)
*/
// anyway, you get the idea. This is also called COBOL because it does on
// thing and truncates every line output to the columns you see with stty -a
// my monitor is huge, so it's not going to work at 80x24. 160x48 is better
// actually, I'd predict some of these will probably end up 240 wide
// long live good eyesight and 4K monitors!
func doCobol() {
log.DaemonMode(true)
if argv.Private {
// GetPrivate()
return
}
if argv.Mine {
log.Printf("get mine %s\n", me.forge.GetGoSrc())
repos := me.forge.Repos.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
if me.forge.Config.IsWritable(repo.GoPath) {
verifyPrint(repo)
}
}
os.Exit(0)
log.Info(standardStart5("gopath", "cur name", "master", "user", "repo type"))
repos := me.found.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
verifyPrint(repo)
}
}
if argv.Favorites {
log.Printf("get favorites\n")
os.Exit(0)
func standardStart5(arg1, arg2, arg3, arg4, arg5 string) string {
len1 := 40
len2 := 12
len3 := 12
len4 := 16
len5 := 8
var s string
if len(arg1) > len1 {
arg1 = arg1[:len1]
}
if argv.List {
var configsave bool
repos := me.forge.Repos.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
if me.forge.Config.IsReadOnly(repo.GoPath) && !argv.ReadOnly {
if repo.ReadOnly {
continue
}
log.Info("todo: ConfigSave() readonly flag on repo is wrong", repo.GoPath)
repo.ReadOnly = true
configsave = true
continue
}
verifyPrint(repo)
}
if configsave {
log.Info("should ConfigSave here")
me.forge.Repos.ConfigSave()
}
os.Exit(0)
s = "%-" + fmt.Sprintf("%d", len1) + "s "
if len(arg2) > len2 {
arg2 = arg2[:len2]
}
s += "%-" + fmt.Sprintf("%d", len2) + "s "
if len(arg3) > len3 {
arg3 = arg3[:len3]
}
s += "%-" + fmt.Sprintf("%d", len3) + "s "
if len(arg4) > len4 {
arg4 = arg4[:len4]
}
s += "%-" + fmt.Sprintf("%d", len4) + "s "
if len(arg5) > len5 {
arg5 = arg5[:len5]
}
s += "%-" + fmt.Sprintf("%d", len5) + "s"
return fmt.Sprintf(s, arg1, arg2, arg3, arg4, arg5)
}
func verifyPrint(repo *gitpb.Repo) {
@ -72,27 +87,20 @@ func verifyPrint(repo *gitpb.Repo) {
os.Exit(0)
}
}
if me.forge.Config.IsReadOnly(repo.GoPath) && !argv.ReadOnly {
if me.forge.Config.IsReadOnly(repo.GoPath) && !argv.FindReadOnly {
if repo.ReadOnly {
return
}
log.Info("readonly flag on repo is wrong", repo.GoPath)
return
}
slen := 12
var chort string = s["cver"]
var mhort string = s["mver"]
var uhort string = s["uver"]
if len(s["cver"]) > slen {
chort = s["cver"][:slen]
}
if len(s["mver"]) > slen {
mhort = s["mver"][:slen]
}
if len(s["uver"]) > slen {
uhort = s["uver"][:slen]
}
start := fmt.Sprintf("%-40s %-12s %-12s %-12s %-8s", s["gopath"], chort, mhort, uhort, s["rtype"])
var cname string = s["cname"]
// start := fmt.Sprintf("%-40s %-12s %-12s %-12s %-8s", s["gopath"], cname, mhort, uhort, s["rtype"])
start := standardStart5(s["gopath"], cname, mhort, uhort, s["rtype"])
if me.forge.Config.IsReadOnly(repo.GoPath) {
end += "(readonly) "
@ -152,29 +160,3 @@ func verify(repo *gitpb.Repo, s map[string]string) bool {
return true
}
func listPrivate() {
repos := me.forge.Repos.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
if me.forge.Config.IsPrivate(repo.GoPath) {
verifyPrint(repo)
}
}
configs := me.forge.Config.SortByGoPath()
for configs.Scan() {
thing := configs.Next()
if thing.Directory {
continue
}
if thing.Private {
found := me.forge.Repos.FindByGoPath(thing.GoPath)
if found == nil {
log.Info("have not downloaded private:", thing.GoPath)
} else {
log.Info("already downloaded private:", thing.GoPath)
}
}
}
os.Exit(0)
}

7
doGitPull.go Normal file
View File

@ -0,0 +1,7 @@
package main
// An app to submit patches for the 30 GO GUI repos
func doGitPull() {
me.found.RillGitPull()
}

40
doGui.go Normal file
View File

@ -0,0 +1,40 @@
package main
// An app to submit patches for the 30 GO GUI repos
import (
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/log"
)
func doGui() {
me.myGui = gui.New()
me.myGui.Default()
me.mainWindow = gadgets.RawBasicWindow("submit & test patchsets")
me.mainWindow.Make()
me.mainWindow.Show()
me.mainbox = me.mainWindow.Box()
// disable the interface while everything is scanned
me.Disable()
vbox2 := me.mainbox.NewVerticalBox("BOX2")
globalBuildOptions(vbox2)
me.summary = submitPatchesBox(vbox2)
me.repos = makeRepoView()
// processing is done. update the repo summary box
me.summary.Update()
me.Enable()
// intermittently scans the status indefinitly
me.repos.View.Watchdog(func() {
log.Info("In main()")
// processing is done. update the repo summary box
me.summary.Update()
})
}

35
doRedoGoMod.go Normal file
View File

@ -0,0 +1,35 @@
package main
// An app to submit patches for the 30 GO GUI repos
import (
"os"
"go.wit.com/log"
)
func doRedoGoMod() {
me.forge.RillRedoGoMod()
os.Exit(0)
repos := me.forge.Repos.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
if !repo.IsValid() {
log.Printf("%10s %-50s", "old?", repo.GetGoPath())
continue
}
log.Printf("running on: %-50s", repo.GetGoPath())
repo.RedoGoMod()
}
}
func doEraseGoMod() {
/*
var cmds [][]string
cmds = append(cmds, []string{"rm", "-f", "go.mod", "go.sum"})
errs := me.forge.RillCmds(me.packs, cmds)
foreach x, y := range errs {
log.Info("EraseGoMod() error", x.GoPath, y)
}
*/
}

5
doScan.go Normal file
View File

@ -0,0 +1,5 @@
package main
func doScan() {
me.forge.ScanGoSrc()
}

85
findConfig.go Normal file
View File

@ -0,0 +1,85 @@
package main
import "go.wit.com/log"
func findPrivate() {
repos := me.forge.Repos.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
if me.forge.Config.IsPrivate(repo.GoPath) {
me.found.AppendUniqueGoPath(repo)
}
}
}
// finds repos that are writable
func findMine() {
log.Printf("get mine %s\n", me.forge.GetGoSrc())
repos := me.forge.Repos.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
if me.forge.Config.IsWritable(repo.GoPath) {
me.found.AppendUniqueGoPath(repo)
}
}
}
// finds repos that are writable
func findFavorites() {
log.Printf("get mine %s\n", me.forge.GetGoSrc())
repos := me.forge.Repos.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
if me.forge.Config.IsFavorite(repo.GoPath) {
me.found.AppendUniqueGoPath(repo)
}
}
}
// retuns true if nothing was done
func findConfig() bool {
if argv.FindMine {
findConfigMine()
return false
}
if argv.FindAll {
findConfigAll()
return false
}
return true
}
// finds config repos that are writable
func findConfigMine() {
loop := me.forge.Config.SortByGoPath()
for loop.Scan() {
r := loop.Next()
gopath := r.GoPath
if r.GetDirectory() {
continue
}
if me.forge.Config.IsWritable(gopath) {
log.Info("mine:", gopath)
me.foundPaths = append(me.foundPaths, gopath)
continue
}
}
}
// get everything in your config
func findConfigAll() {
loop := me.forge.Config.SortByGoPath()
for loop.Scan() {
r := loop.Next()
gopath := r.GoPath
if r.GetDirectory() {
continue
}
if me.forge.Config.IsWritable(gopath) {
log.Info("mine:", gopath)
me.foundPaths = append(me.foundPaths, gopath)
continue
}
}
}

40
findRepos.go Normal file
View File

@ -0,0 +1,40 @@
package main
import (
"go.wit.com/log"
)
func findRepos() {
if argv.FindAll {
var configsave bool
repos := me.forge.Repos.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
if me.forge.Config.IsReadOnly(repo.GoPath) && !argv.FindReadOnly {
if repo.ReadOnly {
continue
}
log.Info("todo: ConfigSave() readonly flag on repo is wrong", repo.GoPath)
repo.ReadOnly = true
configsave = true
continue
}
me.found.AppendUniqueGoPath(repo)
}
if configsave {
log.Info("should ConfigSave here")
me.forge.Repos.ConfigSave()
}
}
if argv.FindPrivate {
findPrivate()
}
if argv.FindMine {
findMine()
}
if argv.FindFavorites {
findFavorites()
}
}

96
main.go
View File

@ -6,11 +6,9 @@ import (
"os"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
"go.wit.com/gui"
)
// sent via -ldflags
@ -23,66 +21,48 @@ func main() {
// load the ~/.config/forge/ config
me.forge = forgepb.Init()
os.Setenv("REPO_WORK_PATH", me.forge.GetGoSrc())
me.found = new(gitpb.Repos)
// show your forge config settings
if argv.ListConf {
me.forge.ConfigPrintTable()
os.Exit(0)
}
// processes any --list like options
// may exit
list()
scan()
if argv.RedoGoMod {
me.forge.RillRedoGoMod()
os.Exit(0)
repos := me.forge.Repos.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
if !repo.IsValid() {
log.Printf("%10s %-50s", "old?", repo.GetGoPath())
continue
}
log.Printf("running on: %-50s", repo.GetGoPath())
if argv.Erase {
repo.EraseGoMod()
} else {
repo.RedoGoMod()
}
// first find the repos or gopaths to operate on
if argv.Config {
if findConfig() {
me.forge.ConfigPrintTable()
os.Exit(0)
}
} else {
findRepos()
}
me.pp.WriteHelp(os.Stdout)
os.Exit(0)
me.myGui = gui.New()
me.myGui.Default()
log.Info("found", me.found.Len(), "repos. found", len(me.foundPaths), "paths from .config/forge")
me.mainWindow = gadgets.RawBasicWindow("submit & test patchsets")
me.mainWindow.Make()
me.mainWindow.Show()
me.mainbox = me.mainWindow.Box()
// now, do something to all of them (or just print out a table of them)
var done bool = false
if argv.DoScan {
doScan()
done = true
}
// disable the interface while everything is scanned
me.Disable()
if argv.DoRedoGoMod {
doRedoGoMod()
done = true
}
if argv.DoGitPull {
doGitPull()
done = true
}
if argv.DoList {
// print out the repos
doCobol()
done = true
}
vbox2 := me.mainbox.NewVerticalBox("BOX2")
globalBuildOptions(vbox2)
me.summary = submitPatchesBox(vbox2)
me.repos = makeRepoView()
// processing is done. update the repo summary box
me.summary.Update()
me.Enable()
// intermittently scans the status indefinitly
me.repos.View.Watchdog(func() {
log.Info("In main()")
// processing is done. update the repo summary box
me.summary.Update()
})
// do the gui at the very end
if argv.DoGui {
doGui()
os.Exit(0)
}
if !done {
// if nothing was selected, print out a table of them on STDOUT
doCobol()
}
}

View File

@ -154,7 +154,7 @@ func (r *repoWindow) mergeAllDevelToMain() bool {
log.Info("skipping dirty", repo.Name(), repo.State())
continue
}
log.Info("found", repo.Name(), repo.State())
log.Info("repo:", repo.Name(), repo.State())
repo.NewScan()
if repo.Status.MergeDevelToMaster() {
log.Warn("THINGS SEEM OK fullAutomation() returned true.")
@ -186,7 +186,7 @@ func (r *repoWindow) mergeAllUserToDevel() bool {
log.Info("skipping dirty", repo.Name(), repo.State())
continue
}
log.Info("found", repo.Name(), repo.State())
log.Info("repo:", repo.Name(), repo.State())
repo.NewScan()
if repo.Status.MergeUserToDevel() {
log.Warn("THINGS SEEM OK fullAutomation() returned true.")

View File

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

View File

@ -20,10 +20,12 @@ func (b *mainType) Enable() {
// this app's variables
type mainType struct {
pp *arg.Parser
forge *forgepb.Forge
myGui *gui.Node
packs []*gitpb.Repo
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
forge *forgepb.Forge // for holding the forge protobuf files
myGui *gui.Node // the gui toolkit handle
found *gitpb.Repos // stores the list of repos to process things on
foundPaths []string // stores gopaths to act on (when doing go-clone)
configSave bool // if the config file should be saved after finishing
// our view of the repositories
repos *repoWindow

View File

@ -176,33 +176,6 @@ func submitPatchesBox(box *gui.Node) *patchSummary {
s.submitB.Disable()
s.grid.NextRow()
/*
// map a path to gitea
s.unknownOL = gadgets.NewBasicEntry(s.grid, "Unknown Repo:")
s.unknownSubmitB = s.grid.NewButton("map new repo path", func() {
log.Info("Submit repo:", s.unknownOL.String())
repo := me.repos.View.FindRepo(s.unknownOL.String())
if repo == nil {
log.Info("could not find repo:", s.unknownOL.String(), "in ~/go/src")
return
}
localurl := repo.GetURL()
log.Info("found repo:", repo.GoPath(), "with giturl", localurl)
if localurl == "" {
log.Info("local repo check failed. repo")
} else {
log.Info("local repo has", localurl)
// check if go.wit.com works, if not, add it
// attempts to register the unknown repo
if gowit.Register(repo.GoPath(), localurl) {
// todo: check if this works
// s.unknownOL.Hide()
// s.unknownSubmitB.Hide()
}
}
})
*/
s.unknownOL.Disable()
s.unknownSubmitB.Disable()
s.grid.NextRow()