From c408a7cca557f8e8933484cff20934564ec70d17 Mon Sep 17 00:00:00 2001
From: Jeff Carr <jcarr@wit.com>
Date: Tue, 23 Jan 2024 11:22:33 -0600
Subject: [PATCH] working towards global branch settings

    repostatus improvements
    common branch handling
    scan all repos
    code cleanups
    check dirty before global delete
    go mod using a quieter gui
    smarter scripting

Signed-off-by: Jeff Carr <jcarr@wit.com>
---
 Makefile                |  1 +
 globalBuildOptions.go   | 24 ++++++----------
 globalResetOptions.go   | 61 ++++++++++++-----------------------------
 globalTestingOptions.go | 36 +++++++++++-------------
 go.mod                  |  4 +--
 go.sum                  | 10 +++----
 main.go                 | 34 ++++++++++++++---------
 repolist.go             |  8 ++----
 scan.go                 |  2 +-
 structs.go              | 28 +++++++++++--------
 unix.go                 | 15 ++--------
 11 files changed, 93 insertions(+), 130 deletions(-)

diff --git a/Makefile b/Makefile
index 3b94bcf..113f2a9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,5 @@
 all: build
+	reset
 	./autotypist
 
 stderr: build
diff --git a/globalBuildOptions.go b/globalBuildOptions.go
index 9942a18..55122b2 100644
--- a/globalBuildOptions.go
+++ b/globalBuildOptions.go
@@ -20,23 +20,17 @@ func doesExist(path string) bool {
 	return true
 }
 
-var quickCmds [][]string
-var quickCmdLastPath string
-var quickCmdDoNotRun bool = false
-
 // only errors on bad errors
 func quickCmd(fullpath string, cmd []string) bool {
 	var err error
 	var b bool
 	var output string
 
-	if quickCmdLastPath != fullpath {
-		quickCmds = append(quickCmds, []string{"cd", fullpath})
-		quickCmdLastPath = fullpath
+	if me.autoWorkingPwd.String() != fullpath {
+		me.autoWorkingPwd.SetValue(fullpath)
 	}
-	quickCmds = append(quickCmds, cmd)
 	log.Warn("RUN:", fullpath, cmd)
-	if quickCmdDoNotRun {
+	if me.autoDryRun.Checked() {
 		return false
 	}
 
@@ -88,14 +82,17 @@ func globalBuildOptions(box *gui.Node) {
 	newBranch.AddText("jcarr")
 	newBranch.SetText("jcarr")
 
+	me.autoWorkingPwd = gadgets.NewOneLiner(grid, "working directory (pwd)")
+
 	group2 := vbox.NewGroup("Run in every git repository")
 	me.stopOnErrors = group2.NewCheckbox("Stop on errors")
 	me.stopOnErrors.SetChecked(true)
 
+	me.autoDryRun = group2.NewCheckbox("autotypist --dry-run")
+	me.autoDryRun.SetChecked(true)
+
 	group2.NewButton("run git status", func() {
-		quickCmdDoNotRun = false
-		quickCmdLastPath = "~/go/src"
-		quickCmds = [][]string{}
+		me.autoWorkingPwd.SetValue("~/go/src")
 		log.Warn("scanning allrepos")
 		for _, path := range me.allrepos {
 			fullpath := "/home/jcarr/go/src/" + path
@@ -104,7 +101,6 @@ func globalBuildOptions(box *gui.Node) {
 	})
 
 	me.rerunGoMod = group2.NewButton("remove go.mod & go.sum", func() {
-		quickCmdDoNotRun = false
 		for _, path := range me.allrepos {
 			fullpath := "/home/jcarr/go/src/" + path
 			if quickCmd(fullpath, []string{"rm", "-f", "go.mod", "go.sum"}) {
@@ -117,7 +113,6 @@ func globalBuildOptions(box *gui.Node) {
 	})
 
 	me.rerunGoMod = group2.NewButton("run go mod & go tidy", func() {
-		quickCmdDoNotRun = false
 		os.Unsetenv("GO111MODULE")
 		for _, path := range me.allrepos {
 			fullpath := "/home/jcarr/go/src/" + path
@@ -127,7 +122,6 @@ func globalBuildOptions(box *gui.Node) {
 	})
 
 	me.rerunGoMod = group2.NewButton("git checkout go.mod & go.sum", func() {
-		quickCmdDoNotRun = false
 		for _, path := range me.allrepos {
 			fullpath := "/home/jcarr/go/src/" + path
 			quickCmd(fullpath, []string{"git", "checkout", "go.mod"})
diff --git a/globalResetOptions.go b/globalResetOptions.go
index fca623c..e7ccfa1 100644
--- a/globalResetOptions.go
+++ b/globalResetOptions.go
@@ -11,54 +11,27 @@ func globalResetOptions(box *gui.Node) {
 
 	buildOptions.NewLabel("start over")
 	buildOptions.NewButton("rm ~/go/src & ~/go/pkg", func() {
-		var newCmds [][]string
-		var dirty bool = false
 		for repo, _ := range me.allrepos {
-			status := repo.getStatus()
-			if status == "dirty" {
-				dirty = true
-				break
+			// status := repo.getStatus()
+			if repo.status.CheckDirty() {
+				log.Warn("repo is dirty. commit your changes first", repo.String())
+				return
+			} else {
+				log.Warn("repo is not dirty", repo.String())
+				log.Warn("TODO: check things are pushed and check every dir in go/src/")
 			}
 		}
-		newCmds = append(newCmds, []string{"cd", "/home/jcarr/"})
-		newCmds = append(newCmds, []string{"rm", "-rf", "go/src/"})
-		newCmds = append(newCmds, []string{"chmod", "700", "-R", "go/pkg/"})
-		newCmds = append(newCmds, []string{"rm", "-rf", "go/pkg/"})
-		if dirty {
-			newCmds = append(newCmds, []string{"can't do this with dirty repos"})
-			doit.Disable()
-		} else {
-			doit.Enable()
-		}
-		me.script = newCmds
-		setGitCommands()
+		/*
+			newCmds = append(newCmds, []string{"cd", "/home/jcarr/"})
+			newCmds = append(newCmds, []string{"rm", "-rf", "go/src/"})
+			newCmds = append(newCmds, []string{"chmod", "700", "-R", "go/pkg/"})
+			newCmds = append(newCmds, []string{"rm", "-rf", "go/pkg/"})
+			if dirty {
+				newCmds = append(newCmds, []string{"can't do this with dirty repos"})
+			} else {
+			}
+		*/
 	})
-
 	buildOptions.NewSeparator("endStatusScans")
 	buildOptions.NewSeparator("endStatusScans")
-
-	// buildOptions.NewLabel("cmd")
-	cmds = group2.NewTextbox("ls")
-
-	buildOptions.NewLabel("--dry-run")
-	dryrun = buildOptions.NewButton("show commands", func() {
-		if goMake("--dry-run") {
-			log.Warn("EVERYTHING MIGHT HAVE WORKED")
-		} else {
-			log.Warn("EVERYTHING WILL NOT WORK")
-			dryrun.Disable()
-		}
-	})
-
-	buildOptions.NewLabel("Doit")
-	doit = buildOptions.NewButton("run commands", func() {
-		doit.Disable()
-		log.Warn("should run the commands here")
-		// true here means dryrun == true. it's confusingly named
-		if goMake("--doit") {
-			log.Warn("EVERYTHING WORKED")
-		} else {
-			log.Warn("EVERYTHING DID NOT WORK")
-		}
-	})
 }
diff --git a/globalTestingOptions.go b/globalTestingOptions.go
index a920b8b..cd183bc 100644
--- a/globalTestingOptions.go
+++ b/globalTestingOptions.go
@@ -21,15 +21,13 @@ func globalTestingOptions(box *gui.Node) {
 		me.autoRebuildButton.SetLabel("rebuild autotypist")
 	})
 
-	var everything *gui.Node
-	everything = test1.NewButton("go get everything on go.wit.com", func() {
-		quickCmdDoNotRun = false
-		quickCmds = [][]string{}
-		quickCmdLastPath = "/home/jcarr/go/src"
+	me.downloadEverythingButton = test1.NewButton("go get go.wit.com", func() {
+		me.downloadEverythingButton.Disable()
+		me.autoWorkingPwd.SetValue("/home/jcarr/go/src")
 		var perfect bool = true
 		repos := myrepolist()
 		for _, line := range repos {
-			log.Warn("repo =", line)
+			log.Verbose("repo =", line)
 			path, _, _, _ := splitLine(line)
 			path = strings.TrimSpace(path)
 			if path == "#" {
@@ -45,19 +43,17 @@ func globalTestingOptions(box *gui.Node) {
 		}
 
 		if perfect {
-			var notes [][]string
-			notes = append(notes, []string{"you have already downloaded"})
-			notes = append(notes, []string{"everything on go.wit.com"})
-			me.script = notes
-			setGitCommands()
-			doit.Disable()
-			everything.Disable()
+			var notes string
+			notes = "you have already downloaded\neverything on go.wit.com"
+			me.autoWorkingPwd.SetValue(notes)
+			me.downloadEverythingButton.Disable()
 			return
+		} else {
+			var notes string
+			notes = "download everything failed"
+			me.autoWorkingPwd.SetValue(notes)
+			me.downloadEverythingButton.Enable()
 		}
-
-		me.script = quickCmds
-		doit.Enable()
-		setGitCommands()
 	})
 	test1.NewButton("build all apps", func() {
 		listWindow()
@@ -65,11 +61,13 @@ func globalTestingOptions(box *gui.Node) {
 	test1.NewButton("repostatus.ListAll()", func() {
 		repostatus.ListAll()
 	})
+	test1.NewButton("repostatus.ScanGoSrc()", func() {
+		repostatus.ScanGoSrc()
+	})
 }
 
 func attemptAutoRebuild() {
 	os.Setenv("GO111MODULE", "off")
-	quickCmdDoNotRun = false
 
 	fullpath := "/home/jcarr/go/"
 	quickCmd(fullpath, []string{"mkdir", "-p", "/home/jcarr/go/src/go.wit.com/apps/"})
@@ -97,6 +95,4 @@ func attemptAutoRebuild() {
 	fullpath = "/home/jcarr/go/src/go.wit.com/apps/autotypist"
 	quickCmd(fullpath, []string{"go", "get", "-v", "-u", "."})
 	quickCmd(fullpath, []string{"go", "build", "-v", "-x"})
-	me.script = quickCmds
-	setGitCommands()
 }
diff --git a/go.mod b/go.mod
index 0317457..48d4141 100644
--- a/go.mod
+++ b/go.mod
@@ -3,9 +3,9 @@ module go.wit.com/apps/autotypist
 go 1.21.4
 
 require (
-	go.wit.com/gui v0.12.19
+	go.wit.com/gui v0.12.20
 	go.wit.com/lib/debugger v0.12.7
-	go.wit.com/lib/gadgets v0.12.15
+	go.wit.com/lib/gadgets v0.12.16
 	go.wit.com/lib/gui/logsettings v0.10.2
 	go.wit.com/lib/gui/repostatus v0.12.20
 	go.wit.com/log v0.5.6
diff --git a/go.sum b/go.sum
index a499b24..145f45d 100644
--- a/go.sum
+++ b/go.sum
@@ -4,16 +4,14 @@ go.wit.com/dev/alexflint/scalar v1.2.1 h1:loXOcbVnd+8YeJRLey+XXidecBiedMDO00zQ26
 go.wit.com/dev/alexflint/scalar v1.2.1/go.mod h1:+rYsfxqdI2cwA8kJ7GCMwWbNJvfvWUurOCXLiwdTtSs=
 go.wit.com/dev/davecgh/spew v1.1.4 h1:C9hj/rjlUpdK+E6aroyLjCbS5MFcyNUOuP1ICLWdNek=
 go.wit.com/dev/davecgh/spew v1.1.4/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA=
-go.wit.com/gui v0.12.19 h1:OEnsnZnec7Q2jZVjwl413V0wuVAAB4r2mGTY0IouBuw=
-go.wit.com/gui v0.12.19/go.mod h1:v2VgnOL3dlZ13KclYeedZ1cd20nQdvwjyJTNKvFX3DA=
+go.wit.com/gui v0.12.20 h1:mIc2DKGcpQjZdgtAj5qzkBrBDiteWfIaEpLyMnIBkh8=
+go.wit.com/gui v0.12.20/go.mod h1:v2VgnOL3dlZ13KclYeedZ1cd20nQdvwjyJTNKvFX3DA=
 go.wit.com/lib/debugger v0.12.7 h1:c8ehU7p2asb//K4YgC17XG4o2pPP+IZb9lR2a0nBio8=
 go.wit.com/lib/debugger v0.12.7/go.mod h1:zcZstsgOcALjCNOiIE+KcKkrIF78ogYjwxmaQlBbmtQ=
-go.wit.com/lib/gadgets v0.12.15 h1:C9q6wc45Trh5SrizD8lOXOWoJLGq/ESWwzjCVylZrNY=
-go.wit.com/lib/gadgets v0.12.15/go.mod h1:Fxc7F8hGskpkWVAsXKhs4ilqUlAnikVXj4yzumtTYa0=
+go.wit.com/lib/gadgets v0.12.16 h1:xHz8zZiTe8xiGvfWs3s9drYUbePTT/Te58u7WXHjx0s=
+go.wit.com/lib/gadgets v0.12.16/go.mod h1:9779QoRZlk+G3/MCcX4Io1eH3HTLImE0AXdAMMdw+0U=
 go.wit.com/lib/gui/logsettings v0.10.2 h1:xRx0AX1V74kC6CIm+ib6C3ziTcbBjR/Ju3rTLEpQMsw=
 go.wit.com/lib/gui/logsettings v0.10.2/go.mod h1:v5XUQ6WyNyfScR9oOFhdz8p1wtxCpNWXK3DJ/dbLPVo=
-go.wit.com/lib/gui/repostatus v0.12.19 h1:Udi1g/gdrDLnKWvXfL5WdyJjRkbFYkEMx56iY9CN+BQ=
-go.wit.com/lib/gui/repostatus v0.12.19/go.mod h1:EO5bI+/cGwHGBQG1S8pDtV58Rmw5HWbW9vZtFLg5Vkw=
 go.wit.com/lib/gui/repostatus v0.12.20 h1:SPx45W8Yd6RZf0oZueXmMhlZsu3MVL8wdb5mVGovbfA=
 go.wit.com/lib/gui/repostatus v0.12.20/go.mod h1:EO5bI+/cGwHGBQG1S8pDtV58Rmw5HWbW9vZtFLg5Vkw=
 go.wit.com/log v0.5.6 h1:rDC3ju95zfEads4f1Zm+QMkqjZ39CsYAT/UmQQs7VP4=
diff --git a/main.go b/main.go
index 4d6501e..9b01df2 100644
--- a/main.go
+++ b/main.go
@@ -16,7 +16,7 @@ import (
 var resToolkit embed.FS
 
 func main() {
-	me = new(repoType)
+	me = new(autoType)
 	me.allrepos = make(map[*repo]string)
 
 	me.myGui = gui.New()
@@ -35,10 +35,15 @@ func main() {
 func addRepo(grid *gui.Node, path string, master string, devel string, user string) {
 	newRepo := new(repo)
 
+	if path == "" {
+		log.Warn("addRepo() got empty path", path, master, devel, user)
+		return
+	}
+
 	if repostatus.VerifyLocalGoRepo(path) {
-		log.Warn("newRepo actually exists", newRepo.getPath())
+		log.Verbose("newRepo actually exists", newRepo.getPath())
 	} else {
-		log.Warn("newRepo does not exist", newRepo.getPath())
+		log.Warn("repostatus.VerifyLocalGoRepo() failed for for", path, master, devel, user)
 		return
 	}
 
@@ -55,7 +60,7 @@ func addRepo(grid *gui.Node, path string, master string, devel string, user stri
 
 	newRepo.vLabel = grid.NewLabel("").SetProgName("current")
 
-	newRepo.showButton = grid.NewButton("Show()", func() {
+	newRepo.statusButton = grid.NewButton("Configure", func() {
 		if newRepo.status == nil {
 			log.Warn("status window doesn't exist")
 			return
@@ -64,17 +69,19 @@ func addRepo(grid *gui.Node, path string, master string, devel string, user stri
 		newRepo.status.Toggle()
 		newRepo.status.Update()
 	})
-	if path == "" {
-		newRepo.cButton.Hide()
-		newRepo.pButton.Hide()
-	}
-	newRepo.status = repostatus.New(me.myGui, newRepo.path)
-	newRepo.status.SetMasterBranchName(master)
+
+	// newRepo.status = repostatus.New(me.myGui, newRepo.path)
+	newRepo.status = repostatus.NewRepoStatusWindow(newRepo.path)
+	newRepo.hidden = false
+	newRepo.status.SetMainWorkingName(me.mainBranch.String())
+	newRepo.status.SetDevelWorkingName(me.develBranch.String())
+	newRepo.status.SetUserWorkingName(me.userBranch.String())
+	/*
 	newRepo.status.SetDevelBranchName(devel)
 	newRepo.status.SetUserBranchName(user)
-	newRepo.hidden = false
 	newRepo.status.Update()
 	newRepo.newScan()
+	*/
 	me.allrepos[newRepo] = path
 }
 
@@ -97,7 +104,8 @@ func repoworld() {
 	reposbox = reposwin.Box().NewBox("bw vbox", false)
 	reposwin.Draw()
 	reposwin.Custom = func() {
-		log.Warn("GOT HERE")
+		log.Warn("GOT HERE: main() gadgets.NewBasicWindow() close")
+		log.Warn("Should I do something special here?")
 	}
 
 	reposgroup = reposbox.NewGroup("go repositories (read from ~/.config/myrepolist)")
@@ -119,7 +127,7 @@ func repoworld() {
 
 	repos := myrepolist()
 	for _, line := range repos {
-		log.Warn("repo =", line)
+		log.Verbose("repo =", line)
 		path, mbranch, dbranch, ubranch := splitLine(line)
 		if mbranch == "" {
 			mbranch = "master"
diff --git a/repolist.go b/repolist.go
index 15b2728..2021aa7 100644
--- a/repolist.go
+++ b/repolist.go
@@ -43,8 +43,6 @@ func myrepolist() []string {
 
 func (r *repo) Hide() {
 	r.pLabel.Hide()
-	r.pButton.Hide()
-	r.cButton.Hide()
 	r.lastTag.Hide()
 	r.vLabel.Hide()
 
@@ -53,14 +51,12 @@ func (r *repo) Hide() {
 	r.userVersion.Hide()
 
 	r.dirtyLabel.Hide()
-	r.showButton.Hide()
+	r.statusButton.Hide()
 	r.hidden = true
 }
 
 func (r *repo) Show() {
 	r.pLabel.Show()
-	r.pButton.Show()
-	r.cButton.Show()
 	r.lastTag.Show()
 	r.vLabel.Show()
 
@@ -69,6 +65,6 @@ func (r *repo) Show() {
 	r.userVersion.Show()
 
 	r.dirtyLabel.Show()
-	r.showButton.Show()
+	r.statusButton.Show()
 	r.hidden = false
 }
diff --git a/scan.go b/scan.go
index 8172d5b..de5e07f 100644
--- a/scan.go
+++ b/scan.go
@@ -14,7 +14,7 @@ func (r *repo) newScan() bool {
 	}
 	// r.scan()
 	if repostatus.VerifyLocalGoRepo(r.getPath()) {
-		log.Warn("repo actually exists", r.getPath())
+		log.Verbose("repo actually exists", r.getPath())
 	} else {
 		log.Warn("repo does not exist", r.getPath())
 		return false
diff --git a/structs.go b/structs.go
index 077bba9..25d819e 100644
--- a/structs.go
+++ b/structs.go
@@ -13,10 +13,9 @@ var reposbox *gui.Node
 var reposgrid *gui.Node
 var reposgroup *gui.Node
 
-var me *repoType
+var me *autoType
 
-type repoType struct {
-	script   [][]string
+type autoType struct {
 	allrepos map[*repo]string
 	myGui    *gui.Node
 
@@ -43,25 +42,34 @@ type repoType struct {
 	// if checked, will stop trying to os.Exec() things after failure
 	stopOnErrors *gui.Node
 
-	autoRebuildButton *gui.Node // button to attempt to autorebuild
+	// button to attempt to autorebuild
+	autoRebuildButton *gui.Node
+
+	// checkbox for --dry-run
+	autoDryRun *gui.Node
+
+	// The current working directory
+	autoWorkingPwd *gadgets.OneLiner
+
+	downloadEverythingButton *gui.Node
 }
 
+/*
 var cmds *gui.Node
 var doit *gui.Node
 var dryrun *gui.Node
+*/
 
 type repo struct {
 	hidden     bool
 	path       string
 	lasttagrev string
 	lasttag    string
-	// tags []string
 
 	pLabel *gui.Node // path label
 	// bLabel *gui.Node // branch label
-	lastTag *gui.Node // last tagged version label
-	vLabel  *gui.Node // version label
-	// tagsDrop *gui.Node // list of all tags
+	lastTag    *gui.Node // last tagged version label
+	vLabel     *gui.Node // version label
 	dirtyLabel *gui.Node // git state (dirty or not?)
 
 	// masterName    *gui.Node // the master branch name
@@ -71,9 +79,7 @@ type repo struct {
 	// userName      *gui.Node // the jcarr branch name
 	userVersion *gui.Node // the jcarr branch version
 
-	cButton    *gui.Node // commit button
-	pButton    *gui.Node // push button
-	showButton *gui.Node // the button!
+	statusButton *gui.Node // opens up the status window
 
 	status *repostatus.RepoStatus
 }
diff --git a/unix.go b/unix.go
index 575c066..2777c74 100644
--- a/unix.go
+++ b/unix.go
@@ -1,5 +1,6 @@
 package main
 
+/*
 import (
 	"strings"
 
@@ -7,7 +8,7 @@ import (
 	"go.wit.com/log"
 )
 
-var repopath string = "/home/jcarr/"
+// var repopath string = "/home/jcarr/"
 
 // if dryRun == true, then it just prints out the values
 // but doesn't do anything
@@ -55,14 +56,4 @@ func goMake(dryRun string) bool {
 	}
 	return true
 }
-
-func setGitCommands() {
-	var tmp []string
-	// convert to displayable to the user text
-	for _, line := range me.script {
-		s := strings.Join(line, " ")
-		log.Warn("s =", s)
-		tmp = append(tmp, s)
-	}
-	cmds.SetText(strings.Join(tmp, "\n"))
-}
+*/