guireleaser/globalBuildOptions.go

203 lines
5.6 KiB
Go
Raw Normal View History

// This is a simple example
package main
import (
"os"
"strings"
"go.wit.com/log"
"go.wit.com/gui"
"go.wit.com/lib/debugger"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/repostatus"
)
func doesExist(path string) bool {
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return false
}
}
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
}
quickCmds = append(quickCmds, cmd)
log.Warn("RUN:", fullpath, cmd)
if quickCmdDoNotRun {
return false
}
err, b, output = repostatus.RunCmd(fullpath, cmd)
if err != nil {
log.Error(err)
return false
} else if !b {
log.Warn("b =", b)
log.Warn("output =", string(output))
return true
}
log.Warn("output = ", string(output))
return true
}
func globalBuildOptions(box *gui.Node) {
var setCurrentBranch *gui.Node
group1 := box.NewGroup("Global Build Options")
groupvbox := group1.NewBox("bw vbox", false)
// grouphbox := groupvbox.NewBox("bw hbox", true)
grid := groupvbox.NewGrid("buildOptions", 2, 1)
me.mainBranch = gadgets.NewBasicCombobox(grid, "default main branch")
me.mainBranch.AddText("guimain")
me.mainBranch.AddText("gitea server default")
me.mainBranch.Disable()
me.develBranch = gadgets.NewBasicCombobox(grid, "default devel branch")
me.develBranch.AddText("devel")
me.userBranch = gadgets.NewBasicCombobox(grid, "default user branch")
me.userBranch.AddText("jcarr")
// select the branch you want to test, build and develop against
// this lets you select your user branch, but, when you are happy
// you can merge everything into the devel branch and make sure it actually
// works. Then, when that is good, merge and version everything in master
guiBranch := gadgets.NewBasicCombobox(grid, "Set Current Working Branch")
guiBranch.AddText("guimaster")
guiBranch.AddText("guidevel")
guiBranch.AddText("jcarr")
guiBranch.Custom = func() {
me.toMoveToBranch = guiBranch.String()
setCurrentBranch.SetLabel("set all branches to " + me.toMoveToBranch)
me.mainBranch.Disable()
}
groupvbox.NewButton("git status", func() {
quickCmdDoNotRun = false
quickCmdLastPath = "~/go/src"
quickCmds = [][]string{}
log.Warn("scanning allrepos")
for _, path := range me.allrepos {
fullpath := "/home/jcarr/go/src/" + path
quickCmd(fullpath, []string{"git", "status"})
}
})
groupvbox.NewButton("rebuild autotypist", func() {
os.Setenv("GO111MODULE", "off")
quickCmdDoNotRun = true
quickCmdLastPath = "~/go/src"
quickCmds = [][]string{}
log.Warn("scanning allrepos")
fullpath := "/home/jcarr/"
quickCmd(fullpath, []string{"mkdir", "-p", "/home/jcarr/go/src/go.wit.com/apps/"})
fullpath = "/home/jcarr/go/src/go.wit.com/apps/"
quickCmd(fullpath, []string{"go", "get", "go.wit.com/apps/autotypist"})
fullpath = "/home/jcarr/go/src/go.wit.com/apps/autotypist"
quickCmd(fullpath, []string{"go", "get", "-v", "go.wit.com/toolkits/debian"})
fullpath = "/home/jcarr/go/src/go.wit.com/toolkits/debian"
quickCmd(fullpath, []string{"make", "download"})
quickCmd(fullpath, []string{"make"})
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()
})
me.rerunGoMod = groupvbox.NewButton("remove all go.mod and go.sum", func() {
quickCmdDoNotRun = false
log.Warn("scanning allrepos")
for _, path := range me.allrepos {
fullpath := "/home/jcarr/go/src/" + path
quickCmd(fullpath, []string{"rm", "-f", "go.mod", "go.sum"})
}
})
me.rerunGoMod = groupvbox.NewButton("re-run go mod & go tidy", func() {
quickCmdDoNotRun = false
os.Unsetenv("GO111MODULE")
log.Warn("scanning allrepos")
for _, path := range me.allrepos {
fullpath := "/home/jcarr/go/src/" + path
quickCmd(fullpath, []string{"go", "mod", "init"})
quickCmd(fullpath, []string{"go", "mod", "tidy"})
}
})
setCurrentBranch = groupvbox.NewButton("set all branches to", func() {
log.Warn("scanning allrepos")
for repo, path := range me.allrepos {
log.Warn("found repo", repo.String())
var changeBranch [][]string
changeBranch = append(changeBranch, []string{"cd", "go/src/" + path})
changeBranch = append(changeBranch, []string{"git", "checkout", me.toMoveToBranch})
me.script = changeBranch
setGitCommands()
// goMake("--doit")
}
})
var everything *gui.Node
everything = groupvbox.NewButton("go get everything on go.wit.com", func() {
quickCmdDoNotRun = false
quickCmds = [][]string{}
var perfect bool = true
repos := myrepolist()
for _, line := range repos {
log.Warn("repo =", line)
path, _, _, _ := splitLine(line)
path = strings.TrimSpace(path)
if path == "#" {
// skip comment lines
continue
}
if doesExist("/home/jcarr/go/src/" + path) {
continue
}
// attempt to download it
quickCmd("/home/jcarr/go/src/go.wit.com", []string{"go", "get", "-v", path})
perfect = false
}
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()
return
}
me.script = quickCmds
doit.Enable()
setGitCommands()
})
groupvbox.NewButton("build all apps", func() {
})
groupvbox.NewButton("Debugger", func() {
debugger.DebugWindow(me.myGui)
})
}