2024-01-16 04:46:17 -06:00
|
|
|
package main
|
|
|
|
|
2024-01-18 00:58:14 -06:00
|
|
|
import (
|
2024-11-13 12:08:58 -06:00
|
|
|
"fmt"
|
2024-01-30 23:38:46 -06:00
|
|
|
"os"
|
2024-01-30 17:22:46 -06:00
|
|
|
"path/filepath"
|
2024-02-21 11:18:16 -06:00
|
|
|
"strconv"
|
2024-02-20 21:03:50 -06:00
|
|
|
"strings"
|
2024-01-30 17:22:46 -06:00
|
|
|
|
2024-01-18 05:03:04 -06:00
|
|
|
"go.wit.com/gui"
|
2024-11-13 12:08:58 -06:00
|
|
|
"go.wit.com/lib/gui/repolist"
|
2024-01-18 00:58:14 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-16 04:46:17 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func globalResetOptions(box *gui.Node) {
|
2024-01-16 11:56:55 -06:00
|
|
|
group2 := box.NewGroup("Global Destructive Options")
|
2024-02-07 13:04:25 -06:00
|
|
|
|
2024-02-24 11:54:47 -06:00
|
|
|
grid := group2.RawGrid()
|
|
|
|
|
2024-11-13 12:08:58 -06:00
|
|
|
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()
|
|
|
|
|
2024-02-24 11:54:47 -06:00
|
|
|
grid.NewButton("delete user branches", func() {
|
|
|
|
os.Setenv("REPO_FORCE", "off")
|
2024-11-13 11:56:58 -06:00
|
|
|
loop := me.repos.View.ReposSortByName()
|
|
|
|
for loop.Scan() {
|
|
|
|
repo := loop.Repo()
|
2024-02-24 11:54:47 -06:00
|
|
|
repo.Status.DeleteUserBranch(false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
grid.NextRow()
|
|
|
|
|
|
|
|
grid.NewButton("delete user branches --force", func() {
|
|
|
|
os.Setenv("REPO_FORCE", "on")
|
2024-11-13 11:56:58 -06:00
|
|
|
loop := me.repos.View.ReposSortByName()
|
|
|
|
for loop.Scan() {
|
|
|
|
repo := loop.Repo()
|
2024-02-24 11:54:47 -06:00
|
|
|
repo.Status.DeleteUserBranch(true)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
grid.NextRow()
|
|
|
|
|
2024-11-13 11:56:58 -06:00
|
|
|
grid.NewButton("git reset all branches", func() {
|
|
|
|
loop := me.repos.View.ReposSortByName()
|
|
|
|
for loop.Scan() {
|
|
|
|
repo := loop.Repo()
|
2024-02-24 11:54:47 -06:00
|
|
|
repo.Status.ResetBranches()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
grid.NextRow()
|
2024-01-16 04:46:17 -06:00
|
|
|
|
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-11-13 11:56:58 -06:00
|
|
|
loop := me.repos.View.ReposSortByName()
|
|
|
|
for loop.Scan() {
|
|
|
|
repo := loop.Repo()
|
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())
|
2024-01-25 11:35:40 -06:00
|
|
|
me.deleteGoSrcPkgB.SetLabel("rm ~/go/src (can't. dirty repos)")
|
2024-01-23 11:22:33 -06:00
|
|
|
return
|
2024-01-16 04:46:17 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-25 11:38:12 -06:00
|
|
|
|
|
|
|
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?" {
|
2024-02-20 20:51:07 -06:00
|
|
|
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" {
|
2024-02-20 20:51:07 -06:00
|
|
|
me.deleteGoSrcPkgB.SetLabel(totals)
|
2024-02-17 15:47:46 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-20 20:51:07 -06:00
|
|
|
if me.deleteGoSrcPkgB.String() == totals {
|
2024-01-30 17:22:46 -06:00
|
|
|
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
|
|
|
|
}
|
2024-01-25 11:38:12 -06:00
|
|
|
}
|
2024-01-16 04:46:17 -06:00
|
|
|
})
|
|
|
|
}
|
2024-01-30 23:38:46 -06:00
|
|
|
|
|
|
|
func attemptAutoRebuild() {
|
2024-02-01 22:00:54 -06:00
|
|
|
os.Setenv("GO111MODULE", "off")
|
2024-01-30 23:38:46 -06:00
|
|
|
|
2024-02-10 16:35:58 -06:00
|
|
|
version := "latest"
|
2024-01-30 23:38:46 -06:00
|
|
|
|
2024-02-01 17:44:06 -06:00
|
|
|
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/")
|
2024-01-30 23:38:46 -06:00
|
|
|
|
2024-02-01 22:00:54 -06:00
|
|
|
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"})
|
2024-01-30 23:38:46 -06:00
|
|
|
|
2024-02-01 22:00:54 -06:00
|
|
|
os.Unsetenv("GO111MODULE")
|
2024-02-01 17:44:06 -06:00
|
|
|
quickCmd(homeDir, []string{"mkdir", "-p", "go/lib"})
|
2024-01-30 23:38:46 -06:00
|
|
|
fullpath = filepath.Join(homeDir, "go/src/go.wit.com/toolkits/nocui/")
|
2024-02-01 17:44:06 -06:00
|
|
|
libfile := filepath.Join(homeDir, "go/lib/nocui.so")
|
2024-02-01 22:00:54 -06:00
|
|
|
quickCmd(fullpath, []string{"go", "mod", "init"})
|
|
|
|
quickCmd(fullpath, []string{"go", "mod", "tidy"})
|
2024-02-01 17:44:06 -06:00
|
|
|
quickCmd(fullpath, []string{"go", "build", "-v", "-x", "-buildmode=plugin", "-o", libfile})
|
2024-01-30 23:38:46 -06:00
|
|
|
|
|
|
|
fullpath = filepath.Join(homeDir, "go/src/go.wit.com/toolkits/gocui/")
|
2024-02-01 17:44:06 -06:00
|
|
|
libfile = filepath.Join(homeDir, "go/lib/gocui.so")
|
2024-02-01 22:00:54 -06:00
|
|
|
quickCmd(fullpath, []string{"go", "mod", "init"})
|
|
|
|
quickCmd(fullpath, []string{"go", "mod", "tidy"})
|
2024-02-01 17:44:06 -06:00
|
|
|
quickCmd(fullpath, []string{"go", "build", "-v", "-x", "-buildmode=plugin", "-o", libfile})
|
2024-01-30 23:38:46 -06:00
|
|
|
|
|
|
|
fullpath = filepath.Join(homeDir, "go/src/go.wit.com/toolkits/andlabs/")
|
2024-02-01 17:44:06 -06:00
|
|
|
libfile = filepath.Join(homeDir, "go/lib/andlabs.so")
|
2024-02-01 22:00:54 -06:00
|
|
|
quickCmd(fullpath, []string{"go", "mod", "init"})
|
|
|
|
quickCmd(fullpath, []string{"go", "mod", "tidy"})
|
2024-02-01 17:44:06 -06:00
|
|
|
quickCmd(fullpath, []string{"go", "build", "-v", "-x", "-buildmode=plugin", "-o", libfile})
|
2024-01-30 23:38:46 -06:00
|
|
|
|
2024-02-01 17:44:06 -06:00
|
|
|
fullpath = filepath.Join(homeDir, "go/src/go.wit.com")
|
2024-02-02 15:22:48 -06:00
|
|
|
quickCmd(fullpath, []string{"go", "install", "-v", "go.wit.com/apps/autotypist@" + version})
|
2024-01-30 23:38:46 -06:00
|
|
|
}
|