175 lines
4.7 KiB
Go
175 lines
4.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"go.wit.com/gui"
|
|
"go.wit.com/lib/gui/repolist"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
func globalResetOptions(box *gui.Node) {
|
|
group2 := box.NewGroup("Global Destructive Options")
|
|
|
|
grid := group2.RawGrid()
|
|
|
|
grid.NewButton("remake 'go.work' file", func() {
|
|
me.autotypistWindow.Disable()
|
|
|
|
goSrcDir := me.goSrcPwd.String()
|
|
filename := filepath.Join(goSrcDir, "go.work")
|
|
|
|
f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
|
|
if err != nil {
|
|
return
|
|
}
|
|
defer f.Close()
|
|
fmt.Fprintln(f, "go 1.21.4")
|
|
fmt.Fprintln(f, "")
|
|
fmt.Fprintln(f, "use (")
|
|
for _, repo := range repolist.AllRepos() {
|
|
if repo.Status.Exists("go.mod") {
|
|
fmt.Fprintln(f, "\t"+repo.Status.GoPath())
|
|
} else {
|
|
log.Info("missing go.mod for", repo.Status.Path())
|
|
// repo.Status.MakeRedomod()
|
|
}
|
|
}
|
|
fmt.Fprintln(f, ")")
|
|
|
|
me.autotypistWindow.Enable()
|
|
})
|
|
grid.NextRow()
|
|
|
|
grid.NewButton("delete user branches", func() {
|
|
os.Setenv("REPO_FORCE", "off")
|
|
loop := me.repos.View.ReposSortByName()
|
|
for loop.Scan() {
|
|
repo := loop.Repo()
|
|
repo.Status.DeleteUserBranch(false)
|
|
}
|
|
})
|
|
grid.NextRow()
|
|
|
|
grid.NewButton("delete user branches --force", func() {
|
|
os.Setenv("REPO_FORCE", "on")
|
|
loop := me.repos.View.ReposSortByName()
|
|
for loop.Scan() {
|
|
repo := loop.Repo()
|
|
repo.Status.DeleteUserBranch(true)
|
|
}
|
|
})
|
|
grid.NextRow()
|
|
|
|
grid.NewButton("git reset all branches", func() {
|
|
loop := me.repos.View.ReposSortByName()
|
|
for loop.Scan() {
|
|
repo := loop.Repo()
|
|
repo.Status.ResetBranches()
|
|
}
|
|
})
|
|
grid.NextRow()
|
|
|
|
grid.NewButton("rm -f go.mod go.sum", func() {
|
|
me.Disable()
|
|
loop := me.repos.View.ReposSortByName()
|
|
for loop.Scan() {
|
|
repo := loop.Repo()
|
|
if repo.Status.Whitelist {
|
|
continue
|
|
}
|
|
if repo.Status.ReadOnly() {
|
|
continue
|
|
}
|
|
repo.Status.Run([]string{"rm", "-f", "go.mod", "go.sum"})
|
|
}
|
|
me.Enable()
|
|
})
|
|
grid.NextRow()
|
|
|
|
grid.NewButton("git reset --hard", func() {
|
|
me.Disable()
|
|
loop := me.repos.View.ReposSortByName()
|
|
for loop.Scan() {
|
|
repo := loop.Repo()
|
|
if repo.Status.Whitelist {
|
|
continue
|
|
}
|
|
if repo.Status.ReadOnly() {
|
|
continue
|
|
}
|
|
repo.Status.Run([]string{"git", "reset", "--hard"})
|
|
}
|
|
me.Enable()
|
|
})
|
|
grid.NextRow()
|
|
|
|
grid.NewLabel("start over")
|
|
me.deleteGoSrcPkgB = grid.NewButton("rm ~/go/src & ~/go/pkg", func() {
|
|
var state string = me.deleteGoSrcPkgB.String()
|
|
loop := me.repos.View.ReposSortByName()
|
|
for loop.Scan() {
|
|
repo := loop.Repo()
|
|
if repo.GoPath() == "go.wit.com/apps/autotypist" {
|
|
continue
|
|
}
|
|
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/")
|
|
if strings.HasPrefix(state, "rm ~/go/src") {
|
|
me.deleteGoSrcPkgB.SetLabel("ARE YOU SURE?")
|
|
return
|
|
}
|
|
if me.deleteGoSrcPkgB.String() == "ARE YOU SURE?" {
|
|
me.deleteGoSrcPkgB.SetLabel("WE ARE NOT KIDDING")
|
|
return
|
|
}
|
|
var totals string = "All " + strconv.Itoa(me.repos.View.TotalGo()) + " Repos?"
|
|
log.Info("totals =", totals)
|
|
if me.deleteGoSrcPkgB.String() == "WE ARE NOT KIDDING" {
|
|
me.deleteGoSrcPkgB.SetLabel(totals)
|
|
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})
|
|
if me.autoDryRun.Checked() {
|
|
me.deleteGoSrcPkgB.SetLabel("rm ~/go/src (uncheck dry-run)")
|
|
return
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func attemptAutoRebuild() {
|
|
gosrc := me.goSrcPwd.String()
|
|
|
|
quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/apps/autotypist"})
|
|
quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/debian"})
|
|
quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/tree"})
|
|
quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/nocui"})
|
|
quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/gocui"})
|
|
quickCmd(gosrc, []string{"go-clone", "--recursive", "go.wit.com/toolkits/andlabs"})
|
|
|
|
quickCmd(filepath.Join(gosrc, "go.wit.com/toolkits/nocui/"), []string{"make"})
|
|
quickCmd(filepath.Join(gosrc, "go.wit.com/toolkits/gocui/"), []string{"make"})
|
|
quickCmd(filepath.Join(gosrc, "go.wit.com/toolkits/andlabs/"), []string{"make"})
|
|
|
|
quickCmd(filepath.Join(gosrc, "go.wit.com/apps/autotypist/"), []string{"make", "build"})
|
|
}
|