summaryrefslogtreecommitdiff
path: root/draw.go
diff options
context:
space:
mode:
Diffstat (limited to 'draw.go')
-rw-r--r--draw.go120
1 files changed, 36 insertions, 84 deletions
diff --git a/draw.go b/draw.go
index e9c52f7..789df45 100644
--- a/draw.go
+++ b/draw.go
@@ -1,11 +1,9 @@
package repostatus
import (
- "path/filepath"
"strconv"
"strings"
- "go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/log"
"go.wit.com/widget"
@@ -13,22 +11,19 @@ import (
// creates the actual widgets.
// it's assumed you are always passing in a box
-func (rs *RepoStatus) draw() {
+func (rs *RepoStatus) draw(goSrcPath string, realPath string) {
if !rs.Ready() {
return
}
// display the status of the git repository
- rs.drawGitStatus()
+ rs.drawGitStatus(goSrcPath, realPath)
// display the git branches and options
rs.drawGitBranches()
// show standard git commit and merge controls
rs.drawGitCommands()
-
- // figure out what the state of the git repository is
- // rs.Update()
}
func (rs *RepoStatus) drawGitBranches() {
@@ -36,19 +31,19 @@ func (rs *RepoStatus) drawGitBranches() {
newgrid := rs.gitBranchesGroup.NewGrid("gridnuts", 2, 2)
rs.masterDrop = gadgets.NewBasicDropdown(newgrid, "main branch")
- rs.masterDrop.Custom = func () {
+ rs.masterDrop.Custom = func() {
log.Log(WARN, "Switching main branch to:", rs.masterDrop.String())
rs.masterBranchVersion.SetLabel(rs.masterDrop.String())
rs.mainWorkingName.SetValue(rs.masterDrop.String())
}
rs.develDrop = gadgets.NewBasicDropdown(newgrid, "devel branch")
- rs.develDrop.Custom = func () {
+ rs.develDrop.Custom = func() {
log.Log(WARN, "Switching devel branch to:", rs.develDrop.String())
rs.develBranchVersion.SetLabel(rs.develDrop.String())
rs.develWorkingName.SetValue(rs.develDrop.String())
}
rs.userDrop = gadgets.NewBasicDropdown(newgrid, "user branch")
- rs.userDrop.Custom = func () {
+ rs.userDrop.Custom = func() {
log.Log(WARN, "Switching user branch to:", rs.userDrop.String())
rs.userBranchVersion.SetLabel(rs.userDrop.String())
rs.userWorkingName.SetValue(rs.userDrop.String())
@@ -63,43 +58,39 @@ func (rs *RepoStatus) drawGitBranches() {
rs.currentBranch = gadgets.NewOneLiner(newgrid, "current branch")
rs.currentVersion = gadgets.NewOneLiner(newgrid, "current version")
- var master = ""
- all := rs.getBranches()
- for _, branch := range all {
- log.Log(INFO, "getBranches()", branch)
- rs.masterDrop.AddText(branch)
- rs.develDrop.AddText(branch)
- rs.userDrop.AddText(branch)
- if branch == "master" {
- master = "master"
- }
- if branch == "main" {
- master = "main"
+ /*
+ var master = ""
+ all := rs.getBranches()
+ for _, branch := range all {
+ log.Log(INFO, "getBranches()", branch)
+ rs.masterDrop.AddText(branch)
+ rs.develDrop.AddText(branch)
+ rs.userDrop.AddText(branch)
+ if branch == "master" {
+ master = "master"
+ }
+ if branch == "main" {
+ master = "main"
+ }
}
- }
+ */
// relabel the various gadgets with the right branch name
- rs.masterBranchVersion.SetLabel(master)
-
- var count *gui.Node
+ // rs.masterBranchVersion.SetLabel(master)
- rs.showBranchesButton = newgrid.NewButton("show branches", func() {
+ rs.showBranchesButton = newgrid.NewButton("getBranches()", func() {
all := rs.getBranches()
i := len(all)
- count.SetText(strconv.Itoa(i) + " branches")
+ log.Log(WARN, "branch count =", i)
})
- count = newgrid.NewLabel("")
- rs.checkBranchesButton = newgrid.NewButton("check branches", func() {
+ rs.checkBranchesButton = newgrid.NewButton("CheckBranches()", func() {
if rs.CheckBranches() {
- log.Log(INFO, "Branches are perfect")
+ log.Log(WARN, "Branches are perfect")
} else {
- log.Log(INFO, "Branches are not perfect")
+ log.Log(WARN, "Branches are not perfect")
}
})
- newgrid.NewButton("parse git and go config", func() {
- ScanGoSrc()
- })
newgrid.NewButton("show .git/config", func() {
if rs.gitConfig == nil {
@@ -110,7 +101,7 @@ func (rs *RepoStatus) drawGitBranches() {
// The info:
for name, remote := range rs.gitConfig.remotes {
- log.Log(WARN, " ", name, remote.url)
+ log.Log(WARN, " ", name, "url:", remote.url)
}
for name, branch := range rs.gitConfig.branches {
log.Log(WARN, " ", name, "remote:", branch.remote, "merge", branch.merge)
@@ -131,54 +122,15 @@ func (rs *RepoStatus) drawGitBranches() {
})
}
-/*
-func (rs *RepoStatus) ScanConfig(path string) {
- log.Log(WARN, "repo =", path)
- filename := filepath.Join(path, ".git/config")
-
- rs.gitConfig, err := ReadGitConfig(filename)
- if err != nil {
- log.Log(WARN, "Error reading .git/config:", err)
- continue
- }
-
- rs.goConfig, err := ReadGoMod(path)
-}
-*/
-
-func ScanGoSrc() {
- for i, path := range listGitDirectories() {
- log.Log(WARN, "repo =", i, path)
- filename := filepath.Join(path, ".git/config")
- gitConfig, err := readGitConfig(filename)
- if err != nil {
- log.Log(WARN, "Error reading .git/config:", err)
- continue
- }
-
- // Example of printing the parsed config
- for section, options := range gitConfig.branches {
- log.Log(WARN, "\t", section, options)
- }
- /*
- _, err = ReadGoMod(path) // map[string]string {
- if err != nil {
- log.Log(WARN, "\tgo.sum scan failed")
- }
- */
-
- }
-}
-
-func (rs *RepoStatus) drawGitStatus() {
+func (rs *RepoStatus) drawGitStatus(goSrcPath string, realPath string) {
rs.gitStatusGroup = rs.window.Box().NewGroup("What GO Knows It Has")
newgrid := rs.gitStatusGroup.NewGrid("gridnuts", 2, 2)
newgrid.Margin()
newgrid.Pad()
rs.path = gadgets.NewOneLiner(newgrid, "path")
- rs.goSrcPath = gadgets.NewOneLiner(newgrid, "go/src")
- rs.realPath = gadgets.NewOneLiner(newgrid, "fullpath")
+ rs.goSrcPath = gadgets.NewOneLiner(newgrid, goSrcPath)
+ rs.realPath = gadgets.NewOneLiner(newgrid, realPath)
rs.realPath.Hide()
rs.mainWorkingName = gadgets.NewOneLiner(newgrid, "main working branch")
rs.mainWorkingName.SetValue("???")
@@ -191,15 +143,15 @@ func (rs *RepoStatus) drawGitStatus() {
// git for-each-ref --sort=taggerdate --format '%(tag) ,,,_,,, %(subject)' refs/tags
var cmd []string
cmd = append(cmd, "git", "for-each-ref", "--sort=taggerdate", "--format", "%(tag) %(subject)", "refs/tags")
- _, _, output := RunCmd("/home/jcarr/go/src/"+rs.repopath, cmd)
+ _, _, output := RunCmd(rs.realPath.String(), cmd)
log.Log(INFO, output)
for _, line := range strings.Split(output, "\n") {
rs.tagsDrop.AddText(line)
}
-// rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master")
-// rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel")
-// rs.userBranchVersion = gadgets.NewOneLiner(newgrid, "user")
+ // rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master")
+ // rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel")
+ // rs.userBranchVersion = gadgets.NewOneLiner(newgrid, "user")
rs.dirtyLabel = gadgets.NewOneLiner(newgrid, "dirty")
@@ -218,7 +170,7 @@ func (rs *RepoStatus) drawGitCommands() {
newgrid.NewButton("git pull", func() {
var cmd []string
cmd = append(cmd, "git", "pull")
- err, b, output := RunCmd("/home/jcarr/go/src/"+rs.repopath, cmd)
+ err, b, output := RunCmd(rs.realPath.String(), cmd)
log.Warn("Did git pull here", err, b, output)
})
@@ -432,7 +384,7 @@ func (rs *RepoStatus) runGitCommands() bool {
s := strings.Join(line, " ")
log.Log(INFO, "NEED TO RUN:", s)
rs.develMerge.SetText(s)
- err, b, output := runCmd(rs.repopath, line)
+ err, b, output := runCmd(rs.realPath.String(), line)
if err != nil {
log.Warn("ABEND EXECUTION")
log.Warn("error =", err)