autotypist/globalResetOptions.go

149 lines
4.8 KiB
Go
Raw Permalink Normal View History

package main
import (
"os"
"path/filepath"
2024-02-21 11:18:16 -06:00
"strconv"
2024-02-20 21:03:50 -06:00
"strings"
"go.wit.com/gui"
2024-02-17 08:38:44 -06:00
"go.wit.com/lib/gui/repolist"
"go.wit.com/log"
)
func globalResetOptions(box *gui.Node) {
group2 := box.NewGroup("Global Destructive Options")
me.autoRebuildButton = group2.NewButton("rebuild autotypist", func() {
me.autoRebuildButton.Disable()
me.autoRebuildButton.SetLabel("running....")
attemptAutoRebuild()
me.autoRebuildButton.Enable()
me.autoRebuildButton.SetLabel("rebuild autotypist")
})
me.stopOnErrors = group2.NewCheckbox("Stop on errors")
me.stopOnErrors.SetChecked(true)
me.autoDryRun = group2.NewCheckbox("autotypist --dry-run")
2024-02-24 11:54:47 -06:00
me.autoDryRun.Custom = func() {
if me.autoDryRun.Checked() {
os.Setenv("REPO_DRYRUN", "on")
} else {
os.Setenv("REPO_DRYRUN", "off")
}
}
me.autoDryRun.SetChecked(true)
2024-02-24 11:54:47 -06:00
grid := group2.RawGrid()
grid.NewButton("delete user branches", func() {
os.Setenv("REPO_FORCE", "off")
for _, repo := range repolist.AllRepos() {
repo.Status.DeleteUserBranch(false)
}
})
grid.NextRow()
grid.NewButton("delete user branches --force", func() {
os.Setenv("REPO_FORCE", "on")
for _, repo := range repolist.AllRepos() {
repo.Status.DeleteUserBranch(true)
}
})
grid.NextRow()
grid.NewButton("reset all branches", func() {
for _, repo := range repolist.AllRepos() {
repo.Status.ResetBranches()
}
})
grid.NextRow()
2024-02-24 11:54:47 -06:00
grid.NewLabel("start over")
me.deleteGoSrcPkgB = grid.NewButton("rm ~/go/src & ~/go/pkg", func() {
2024-02-20 21:03:50 -06:00
var state string = me.deleteGoSrcPkgB.String()
2024-02-17 08:38:44 -06:00
for _, repo := range repolist.AllRepos() {
2024-02-20 21:03:50 -06:00
if repo.GoPath() == "go.wit.com/apps/autotypist" {
continue
}
2024-02-17 15:47:46 -06:00
if repo.Status.CheckDirty() {
log.Warn("repo is dirty. commit your changes first", repo.Status.Path())
me.deleteGoSrcPkgB.SetLabel("rm ~/go/src (can't. dirty repos)")
return
}
}
log.Warn("no repos have uncommited changes")
log.Warn("TODO: check things are pushed and check every dir in go/src/")
2024-02-20 21:03:50 -06:00
if strings.HasPrefix(state, "rm ~/go/src") {
me.deleteGoSrcPkgB.SetLabel("ARE YOU SURE?")
return
}
2024-02-17 15:47:46 -06:00
if me.deleteGoSrcPkgB.String() == "ARE YOU SURE?" {
me.deleteGoSrcPkgB.SetLabel("WE ARE NOT KIDDING")
2024-02-17 15:47:46 -06:00
return
}
2024-02-21 11:18:16 -06:00
var totals string = "All " + strconv.Itoa(me.repos.View.TotalGo()) + " Repos?"
2024-02-20 21:03:50 -06:00
log.Info("totals =", totals)
2024-02-17 15:47:46 -06:00
if me.deleteGoSrcPkgB.String() == "WE ARE NOT KIDDING" {
me.deleteGoSrcPkgB.SetLabel(totals)
2024-02-17 15:47:46 -06:00
return
}
if me.deleteGoSrcPkgB.String() == totals {
homeDir := me.userHomePwd.String()
fullpath := filepath.Join(homeDir, "go")
gosrc := filepath.Join(fullpath, "src")
gopkg := filepath.Join(fullpath, "pkg")
quickCmd(fullpath, []string{"rm", "-rf", gosrc})
quickCmd(fullpath, []string{"chmod", "700", "-R", gopkg})
quickCmd(fullpath, []string{"rm", "-rf", gopkg})
2024-02-20 21:03:50 -06:00
if me.autoDryRun.Checked() {
me.deleteGoSrcPkgB.SetLabel("rm ~/go/src (uncheck dry-run)")
return
}
}
})
}
func attemptAutoRebuild() {
os.Setenv("GO111MODULE", "off")
version := "latest"
homeDir := me.userHomePwd.String()
quickCmd(homeDir, []string{"mkdir", "-p", "go/src/go.wit.com/apps/"})
fullpath := filepath.Join(homeDir, "go/src/go.wit.com/apps/")
quickCmd(fullpath, []string{"go", "get", "-v", "go.wit.com/apps/autotypist"})
quickCmd(fullpath, []string{"go", "get", "-v", "go.wit.com/toolkits/debian"})
quickCmd(fullpath, []string{"go", "get", "-v", "go.wit.com/toolkits/tree"})
quickCmd(fullpath, []string{"go", "get", "-v", "go.wit.com/toolkits/nocui"})
quickCmd(fullpath, []string{"go", "get", "-v", "go.wit.com/toolkits/gocui"})
quickCmd(fullpath, []string{"go", "get", "-v", "go.wit.com/toolkits/andlabs"})
os.Unsetenv("GO111MODULE")
quickCmd(homeDir, []string{"mkdir", "-p", "go/lib"})
fullpath = filepath.Join(homeDir, "go/src/go.wit.com/toolkits/nocui/")
libfile := filepath.Join(homeDir, "go/lib/nocui.so")
quickCmd(fullpath, []string{"go", "mod", "init"})
quickCmd(fullpath, []string{"go", "mod", "tidy"})
quickCmd(fullpath, []string{"go", "build", "-v", "-x", "-buildmode=plugin", "-o", libfile})
fullpath = filepath.Join(homeDir, "go/src/go.wit.com/toolkits/gocui/")
libfile = filepath.Join(homeDir, "go/lib/gocui.so")
quickCmd(fullpath, []string{"go", "mod", "init"})
quickCmd(fullpath, []string{"go", "mod", "tidy"})
quickCmd(fullpath, []string{"go", "build", "-v", "-x", "-buildmode=plugin", "-o", libfile})
fullpath = filepath.Join(homeDir, "go/src/go.wit.com/toolkits/andlabs/")
libfile = filepath.Join(homeDir, "go/lib/andlabs.so")
quickCmd(fullpath, []string{"go", "mod", "init"})
quickCmd(fullpath, []string{"go", "mod", "tidy"})
quickCmd(fullpath, []string{"go", "build", "-v", "-x", "-buildmode=plugin", "-o", libfile})
fullpath = filepath.Join(homeDir, "go/src/go.wit.com")
quickCmd(fullpath, []string{"go", "install", "-v", "go.wit.com/apps/autotypist@" + version})
}