summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--args.go8
-rw-r--r--common.go32
-rw-r--r--draw.go56
-rw-r--r--git.go8
-rw-r--r--new.go16
-rw-r--r--structs.go68
-rw-r--r--timer.go8
-rw-r--r--unix.go16
-rw-r--r--update.go10
9 files changed, 121 insertions, 101 deletions
diff --git a/args.go b/args.go
index d342ac8..8cea172 100644
--- a/args.go
+++ b/args.go
@@ -4,7 +4,7 @@ package repostatus
this enables command line options from other packages like 'gui' and 'log'
*/
-import (
+import (
"go.wit.com/log"
)
@@ -21,12 +21,12 @@ func init() {
full := "go.wit.com/gui/gadgets/repostatus"
short := "repostatus"
- NOW = log.NewFlag( "NOW", true, full, short, "temp debugging stuff")
+ NOW = log.NewFlag("NOW", true, full, short, "temp debugging stuff")
INFO = log.NewFlag("INFO", false, full, short, "normal debugging stuff")
- WARN = log.NewFlag("WARN", true, full, short, "bad things")
+ WARN = log.NewFlag("WARN", true, full, short, "bad things")
SPEW = log.NewFlag("SPEW", false, full, short, "spew stuff")
- CHANGE = log.NewFlag("CHANGE", true, full, short, "when repo changes")
+ CHANGE = log.NewFlag("CHANGE", true, full, short, "when repo changes")
STATUS = log.NewFlag("STATUS", false, full, short, "current status")
}
diff --git a/common.go b/common.go
index 6f58793..0ec5cb8 100644
--- a/common.go
+++ b/common.go
@@ -1,14 +1,16 @@
package repostatus
-import (
+import (
"go.wit.com/log"
-// "go.wit.com/gui/gui"
+ // "go.wit.com/gui/gui"
)
// reports externally if something has changed
// since the last time it was asked about it
func (rs *RepoStatus) Changed() bool {
- if ! rs.Ready() {return false}
+ if !rs.Ready() {
+ return false
+ }
if rs.changed {
rs.changed = false
return true
@@ -17,7 +19,9 @@ func (rs *RepoStatus) Changed() bool {
}
func (rs *RepoStatus) Draw() {
- if ! rs.Ready() {return}
+ if !rs.Ready() {
+ return
+ }
log.Log(CHANGE, "Draw() window ready =", rs.ready)
rs.window.TestDraw()
// rs.window.Draw()
@@ -25,21 +29,27 @@ func (rs *RepoStatus) Draw() {
}
func (rs *RepoStatus) Show() {
- if ! rs.Ready() {return}
+ if !rs.Ready() {
+ return
+ }
log.Log(CHANGE, "Show() window ready =", rs.ready)
rs.window.Show()
rs.hidden = false
}
func (rs *RepoStatus) Hide() {
- if ! rs.Ready() {return}
+ if !rs.Ready() {
+ return
+ }
log.Log(CHANGE, "Hide() window ready =", rs.ready)
rs.window.Hide()
rs.hidden = true
}
func (rs *RepoStatus) Toggle() {
- if ! rs.Ready() {return}
+ if !rs.Ready() {
+ return
+ }
log.Log(CHANGE, "Toggle() window ready =", rs.ready)
if rs.hidden {
rs.Show()
@@ -50,8 +60,12 @@ func (rs *RepoStatus) Toggle() {
func (rs *RepoStatus) Ready() bool {
log.Log(SPEW, "Ready() maybe not ready? rs =", rs)
- if rs == nil {return false}
- if rs.window == nil {return false}
+ if rs == nil {
+ return false
+ }
+ if rs.window == nil {
+ return false
+ }
return rs.ready
}
diff --git a/draw.go b/draw.go
index 9047808..707abe4 100644
--- a/draw.go
+++ b/draw.go
@@ -1,19 +1,21 @@
package repostatus
-import (
+import (
"strconv"
"strings"
- "go.wit.com/log"
"go.wit.com/gui/gui"
- "go.wit.com/gui/widget"
- "go.wit.com/gui/gadgets"
+ "go.wit.com/lib/gadgets"
+ "go.wit.com/lib/widget"
+ "go.wit.com/log"
)
// creates the actual widgets.
// it's assumed you are always passing in a box
func (rs *RepoStatus) draw() {
- if ! rs.Ready() {return}
+ if !rs.Ready() {
+ return
+ }
// display the status of the git repository
rs.drawGitStatus()
@@ -33,8 +35,8 @@ func (rs *RepoStatus) drawGitBranches() {
newgrid := rs.gitBranchesGroup.NewGrid("gridnuts", 2, 2)
rs.masterDrop = gadgets.NewBasicDropdown(newgrid, "main branch")
- rs.develDrop = gadgets.NewBasicDropdown(newgrid, "devel branch")
- rs.userDrop = gadgets.NewBasicDropdown(newgrid, "user branch")
+ rs.develDrop = gadgets.NewBasicDropdown(newgrid, "devel branch")
+ rs.userDrop = gadgets.NewBasicDropdown(newgrid, "user branch")
var master = ""
all := rs.getBranches()
for _, branch := range all {
@@ -77,19 +79,19 @@ func (rs *RepoStatus) drawGitStatus() {
newgrid.Margin()
newgrid.Pad()
- rs.path = gadgets.NewOneLiner(newgrid, "path")
- rs.currentBranch = gadgets.NewOneLiner(newgrid, "branch")
- rs.lasttag = gadgets.NewOneLiner(newgrid, "last tag")
- rs.currentVersion = gadgets.NewOneLiner(newgrid, "Version")
- rs.tagsDrop = gadgets.NewBasicDropdown(newgrid, "existing tags")
- rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master")
- rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel")
- rs.userBranchVersion = gadgets.NewOneLiner(newgrid, "user")
+ rs.path = gadgets.NewOneLiner(newgrid, "path")
+ rs.currentBranch = gadgets.NewOneLiner(newgrid, "branch")
+ rs.lasttag = gadgets.NewOneLiner(newgrid, "last tag")
+ rs.currentVersion = gadgets.NewOneLiner(newgrid, "Version")
+ rs.tagsDrop = gadgets.NewBasicDropdown(newgrid, "existing tags")
+ rs.masterBranchVersion = gadgets.NewOneLiner(newgrid, "master")
+ rs.develBranchVersion = gadgets.NewOneLiner(newgrid, "devel")
+ rs.userBranchVersion = gadgets.NewOneLiner(newgrid, "user")
- rs.dirtyLabel = gadgets.NewOneLiner(newgrid, "dirty")
+ rs.dirtyLabel = gadgets.NewOneLiner(newgrid, "dirty")
- rs.speed = gadgets.NewOneLiner(newgrid, "refresh speed =")
- rs.speedActual = gadgets.NewOneLiner(newgrid, "speed actual =")
+ rs.speed = gadgets.NewOneLiner(newgrid, "refresh speed =")
+ rs.speedActual = gadgets.NewOneLiner(newgrid, "speed actual =")
}
func (rs *RepoStatus) drawGitCommands() {
@@ -109,7 +111,7 @@ func (rs *RepoStatus) drawGitCommands() {
log.Warn("something went wrong switching to the master branch. full stop!")
return
}
- if ! rs.runGitCommands() {
+ if !rs.runGitCommands() {
log.Warn("SOMETHING WENT WRONG")
return
}
@@ -118,17 +120,17 @@ func (rs *RepoStatus) drawGitCommands() {
})
rs.major = gadgets.NewBasicCombobox(newgrid, "major")
- rs.major.Custom = func () {
+ rs.major.Custom = func() {
rs.setTag()
rs.generateCmd()
}
rs.minor = gadgets.NewBasicCombobox(newgrid, "minor")
- rs.minor.Custom = func () {
+ rs.minor.Custom = func() {
rs.setTag()
rs.generateCmd()
}
rs.revision = gadgets.NewBasicCombobox(newgrid, "revision")
- rs.revision.Custom = func () {
+ rs.revision.Custom = func() {
rs.setTag()
rs.generateCmd()
}
@@ -136,19 +138,19 @@ func (rs *RepoStatus) drawGitCommands() {
rs.newversion = newgrid.NewLabel("3.1.4")
rs.versionMessage = gadgets.NewBasicEntry(newgrid, "tag message")
- rs.versionMessage.Custom = func () {
+ rs.versionMessage.Custom = func() {
rs.generateCmd()
}
rs.versionCmdOutput = gadgets.NewOneLiner(newgrid, "tag cmd")
rs.releaseVersion = newgrid.NewButton("tag and release new version", func() {
- if ! rs.generateCmd() {
+ if !rs.generateCmd() {
log.Warn("something is wrong. fix the errors first")
return
}
rs.releaseVersion.Disable()
log.Warn("COMMIT IT HERE")
- if ! rs.runGitCommands() {
+ if !rs.runGitCommands() {
log.Warn("SOMETHING WENT WRONG")
}
rs.Update()
@@ -280,7 +282,7 @@ func (rs *RepoStatus) generateCmd() bool {
// or something the users might see.
// aka: "Topsy", "Picasso", "Buzz", etc
- if ! rs.setTag() {
+ if !rs.setTag() {
log.Warn("tag sucked. fix your tag version")
rs.versionMessage.SetLabel("tag message (bad version)")
rs.releaseVersion.Disable()
@@ -328,7 +330,7 @@ func (rs *RepoStatus) setGitCommands() {
var all [][]string
newTag := rs.newversion.String()
- line1 = append(line1, "git", "tag", "v" + newTag, "-m", rs.versionMessage.String())
+ line1 = append(line1, "git", "tag", "v"+newTag, "-m", rs.versionMessage.String())
all = append(all, line1)
line2 = append(line2, "git", "push", "--tags")
all = append(all, line2)
diff --git a/git.go b/git.go
index 7fa6b98..31175b6 100644
--- a/git.go
+++ b/git.go
@@ -4,8 +4,8 @@ import (
"strings"
"unicode/utf8"
- "io/ioutil"
"go.wit.com/log"
+ "io/ioutil"
)
func (rs *RepoStatus) GetPath() string {
@@ -133,8 +133,8 @@ func (rs *RepoStatus) checkoutBranch(level string, branch string) {
log.Warn("checkoutBranch() checkDirty() == true for repo", rs.repopath, "looking for branch:", branch)
return
}
- out := run(rs.repopath, "git", "checkout " + branch)
- log.Warn(rs.repopath, "git checkout " + branch, "returned", out)
+ out := run(rs.repopath, "git", "checkout "+branch)
+ log.Warn(rs.repopath, "git checkout "+branch, "returned", out)
realname := rs.getCurrentBranchName()
realversion := rs.getCurrentBranchVersion()
@@ -232,7 +232,7 @@ func (rs *RepoStatus) CheckBranches() bool {
}
var cmd []string
cmd = append(cmd, "git", "show", "-s", "--format=%ci", hash)
- _, _, output := RunCmd("/home/jcarr/go/src/" + rs.repopath, cmd)
+ _, _, output := RunCmd("/home/jcarr/go/src/"+rs.repopath, cmd)
// git show -s --format=%ci <hash> will give you the time
// log.Warn(fullfile)
if hash == hashCheck {
diff --git a/new.go b/new.go
index d722136..6242987 100644
--- a/new.go
+++ b/new.go
@@ -1,20 +1,20 @@
package repostatus
-import (
- "go.wit.com/log"
+import (
"go.wit.com/gui/gui"
- "go.wit.com/gui/gadgets"
+ "go.wit.com/lib/gadgets"
+ "go.wit.com/log"
)
func New(p *gui.Node, path string) *RepoStatus {
- rs := &RepoStatus {
- hidden: true,
- ready: false,
- parent: p,
+ rs := &RepoStatus{
+ hidden: true,
+ ready: false,
+ parent: p,
repopath: path,
}
rs.tags = make(map[string]string)
- rs.window = gadgets.NewBasicWindow(p, "GO Repo Details " + path)
+ rs.window = gadgets.NewBasicWindow(p, "GO Repo Details "+path)
rs.window.Horizontal()
rs.window.Make()
rs.ready = true
diff --git a/structs.go b/structs.go
index 76cbc0c..e30c133 100644
--- a/structs.go
+++ b/structs.go
@@ -2,62 +2,62 @@ package repostatus
import (
"go.wit.com/gui/gui"
- "go.wit.com/gui/gadgets"
+ "go.wit.com/lib/gadgets"
)
type RepoStatus struct {
- ready bool
- hidden bool
- changed bool
+ ready bool
+ hidden bool
+ changed bool
- repopath string
+ repopath string
lasttagrev string
- tags map[string]string
+ tags map[string]string
- parent *gui.Node
+ parent *gui.Node
- window *gadgets.BasicWindow
+ window *gadgets.BasicWindow
// group *gui.Node
// grid *gui.Node
-// status *gadgets.OneLiner
- dirtyLabel *gadgets.OneLiner
- path *gadgets.OneLiner
+ // status *gadgets.OneLiner
+ dirtyLabel *gadgets.OneLiner
+ path *gadgets.OneLiner
- currentBranch *gadgets.OneLiner
- currentVersion *gadgets.OneLiner
- tagsDrop *gadgets.BasicDropdown
+ currentBranch *gadgets.OneLiner
+ currentVersion *gadgets.OneLiner
+ tagsDrop *gadgets.BasicDropdown
- lasttag *gadgets.OneLiner
- masterBranchVersion *gadgets.OneLiner
- develBranchVersion *gadgets.OneLiner
- userBranchVersion *gadgets.OneLiner
+ lasttag *gadgets.OneLiner
+ masterBranchVersion *gadgets.OneLiner
+ develBranchVersion *gadgets.OneLiner
+ userBranchVersion *gadgets.OneLiner
- develMerge *gui.Node
- releaseVersion *gui.Node
+ develMerge *gui.Node
+ releaseVersion *gui.Node
-// vgroup *gui.Node
- minor *gadgets.BasicCombobox
- major *gadgets.BasicCombobox
- revision *gadgets.BasicCombobox
+ // vgroup *gui.Node
+ minor *gadgets.BasicCombobox
+ major *gadgets.BasicCombobox
+ revision *gadgets.BasicCombobox
- versionMessage *gadgets.BasicEntry
- versionCmds [][]string
+ versionMessage *gadgets.BasicEntry
+ versionCmds [][]string
versionCmdOutput *gadgets.OneLiner
- newversion *gui.Node
+ newversion *gui.Node
gitBranchesGroup *gui.Node
- gitStatusGroup *gui.Node
+ gitStatusGroup *gui.Node
gitCommandsGroup *gui.Node
- masterDrop *gadgets.BasicDropdown
- develDrop *gadgets.BasicDropdown
- userDrop *gadgets.BasicDropdown
+ masterDrop *gadgets.BasicDropdown
+ develDrop *gadgets.BasicDropdown
+ userDrop *gadgets.BasicDropdown
- showBranchesButton *gui.Node
+ showBranchesButton *gui.Node
checkBranchesButton *gui.Node
- speed *gadgets.OneLiner
- speedActual *gadgets.OneLiner
+ speed *gadgets.OneLiner
+ speedActual *gadgets.OneLiner
}
diff --git a/timer.go b/timer.go
index 0ba5faf..380e4bb 100644
--- a/timer.go
+++ b/timer.go
@@ -6,12 +6,14 @@ import (
// timeFunction takes a function as an argument and returns the execution time.
func timeFunction(f func()) time.Duration {
- startTime := time.Now() // Record the start time
- f() // Execute the function
+ startTime := time.Now() // Record the start time
+ f() // Execute the function
return time.Since(startTime) // Calculate the elapsed time
}
func (ls *RepoStatus) SetSpeedActual(s string) {
- if ! ls.Ready() {return}
+ if !ls.Ready() {
+ return
+ }
ls.speedActual.SetText(s)
}
diff --git a/unix.go b/unix.go
index 7ef0fed..716798e 100644
--- a/unix.go
+++ b/unix.go
@@ -1,14 +1,14 @@
// This is a simple example
package repostatus
-import (
+import (
+ "errors"
"os"
"os/exec"
"os/user"
- "strings"
- "regexp"
- "errors"
"path/filepath"
+ "regexp"
+ "strings"
"go.wit.com/log"
)
@@ -54,8 +54,8 @@ func listFiles(directory string) []string {
dirname := file.Name()
newdir, _ := os.ReadDir(directory + "/" + dirname)
for _, file := range newdir {
- if ! file.IsDir() {
- files = append(files, dirname + "/" + file.Name())
+ if !file.IsDir() {
+ files = append(files, dirname+"/"+file.Name())
}
}
} else {
@@ -91,7 +91,9 @@ func alphaOnly(s string) bool {
func normalizeVersion(s string) string {
// reg, err := regexp.Compile("[^a-zA-Z0-9]+")
parts := strings.Split(s, "-")
- if len(parts) == 0 { return "" }
+ if len(parts) == 0 {
+ return ""
+ }
reg, err := regexp.Compile("[^0-9.]+")
if err != nil {
log.Log(WARN, "normalizeVersion() regexp.Compile() ERROR =", err)
diff --git a/update.go b/update.go
index 892ebfb..060f879 100644
--- a/update.go
+++ b/update.go
@@ -1,21 +1,21 @@
package repostatus
import (
+ "errors"
"fmt"
"time"
- "errors"
"go.wit.com/log"
)
func (rs *RepoStatus) Update() {
- if ! rs.Ready() {
+ if !rs.Ready() {
log.Log(WARN, "can't update yet. ready is false")
log.Error(errors.New("Update() is not ready yet"))
return
}
log.Log(WARN, "Update() START")
- duration := timeFunction(func () {
+ duration := timeFunction(func() {
// do things that are safe even if the git tree is dirty
log.Warn("path.SetText()")
rs.path.SetText(rs.repopath)
@@ -67,9 +67,9 @@ func (rs *RepoStatus) setSpeed(duration time.Duration) {
}
rs.speedActual.SetText(s)
- if (duration > 500 * time.Millisecond ) {
+ if duration > 500*time.Millisecond {
rs.speed.SetText("SLOW")
- } else if (duration > 100 * time.Millisecond ) {
+ } else if duration > 100*time.Millisecond {
rs.speed.SetText("OK")
} else {
rs.speed.SetText("FAST")