summaryrefslogtreecommitdiff
path: root/globalBuildOptions.go
blob: 9942a187653c570568b12458b674f68e1297278b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// This is a simple example
package main

import (
	"os"

	"go.wit.com/log"

	"go.wit.com/gui"
	"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) {
	vbox := box.NewVerticalBox("DISPLAYVBOX")
	group1 := vbox.NewGroup("Global Build Options")
	grid := group1.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
	var newBranch *gui.Node
	grid.NewButton("set all branches to", func() {
		log.Warn("set all branches to:", newBranch.String())
		/*
			me.toMoveToBranch = guiBranch.String()
			setCurrentBranch.SetLabel("set all branches to " + me.toMoveToBranch)
			me.mainBranch.Disable()
		*/
	})
	newBranch = grid.NewCombobox()
	newBranch.AddText("guimaster")
	newBranch.AddText("guidevel")
	newBranch.AddText("jcarr")
	newBranch.SetText("jcarr")

	group2 := vbox.NewGroup("Run in every git repository")
	me.stopOnErrors = group2.NewCheckbox("Stop on errors")
	me.stopOnErrors.SetChecked(true)

	group2.NewButton("run 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"})
		}
	})

	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"}) {
				log.Info("rm go.mod FAILED in repo", fullpath, me.stopOnErrors.Bool())
				if me.stopOnErrors.Bool() {
					return
				}
			}
		}
	})

	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
			quickCmd(fullpath, []string{"go", "mod", "init"})
			quickCmd(fullpath, []string{"go", "mod", "tidy"})
		}
	})

	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"})
			quickCmd(fullpath, []string{"git", "checkout", "go.sum"})
		}
	})
}