gofmt autofix paths

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-18 00:57:43 -06:00
parent 47a665be8b
commit ff3a51f354
9 changed files with 121 additions and 101 deletions

View File

@ -21,7 +21,7 @@ func init() {
full := "go.wit.com/gui/gadgets/repostatus" full := "go.wit.com/gui/gadgets/repostatus"
short := "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") 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")

View File

@ -2,13 +2,15 @@ package repostatus
import ( import (
"go.wit.com/log" "go.wit.com/log"
// "go.wit.com/gui/gui" // "go.wit.com/gui/gui"
) )
// reports externally if something has changed // reports externally if something has changed
// since the last time it was asked about it // since the last time it was asked about it
func (rs *RepoStatus) Changed() bool { func (rs *RepoStatus) Changed() bool {
if ! rs.Ready() {return false} if !rs.Ready() {
return false
}
if rs.changed { if rs.changed {
rs.changed = false rs.changed = false
return true return true
@ -17,7 +19,9 @@ func (rs *RepoStatus) Changed() bool {
} }
func (rs *RepoStatus) Draw() { func (rs *RepoStatus) Draw() {
if ! rs.Ready() {return} if !rs.Ready() {
return
}
log.Log(CHANGE, "Draw() window ready =", rs.ready) log.Log(CHANGE, "Draw() window ready =", rs.ready)
rs.window.TestDraw() rs.window.TestDraw()
// rs.window.Draw() // rs.window.Draw()
@ -25,21 +29,27 @@ func (rs *RepoStatus) Draw() {
} }
func (rs *RepoStatus) Show() { func (rs *RepoStatus) Show() {
if ! rs.Ready() {return} if !rs.Ready() {
return
}
log.Log(CHANGE, "Show() window ready =", rs.ready) log.Log(CHANGE, "Show() window ready =", rs.ready)
rs.window.Show() rs.window.Show()
rs.hidden = false rs.hidden = false
} }
func (rs *RepoStatus) Hide() { func (rs *RepoStatus) Hide() {
if ! rs.Ready() {return} if !rs.Ready() {
return
}
log.Log(CHANGE, "Hide() window ready =", rs.ready) log.Log(CHANGE, "Hide() window ready =", rs.ready)
rs.window.Hide() rs.window.Hide()
rs.hidden = true rs.hidden = true
} }
func (rs *RepoStatus) Toggle() { func (rs *RepoStatus) Toggle() {
if ! rs.Ready() {return} if !rs.Ready() {
return
}
log.Log(CHANGE, "Toggle() window ready =", rs.ready) log.Log(CHANGE, "Toggle() window ready =", rs.ready)
if rs.hidden { if rs.hidden {
rs.Show() rs.Show()
@ -50,8 +60,12 @@ func (rs *RepoStatus) Toggle() {
func (rs *RepoStatus) Ready() bool { func (rs *RepoStatus) Ready() bool {
log.Log(SPEW, "Ready() maybe not ready? rs =", rs) log.Log(SPEW, "Ready() maybe not ready? rs =", rs)
if rs == nil {return false} if rs == nil {
if rs.window == nil {return false} return false
}
if rs.window == nil {
return false
}
return rs.ready return rs.ready
} }

28
draw.go
View File

@ -4,16 +4,18 @@ import (
"strconv" "strconv"
"strings" "strings"
"go.wit.com/log"
"go.wit.com/gui/gui" "go.wit.com/gui/gui"
"go.wit.com/gui/widget" "go.wit.com/lib/gadgets"
"go.wit.com/gui/gadgets" "go.wit.com/lib/widget"
"go.wit.com/log"
) )
// creates the actual widgets. // creates the actual widgets.
// it's assumed you are always passing in a box // it's assumed you are always passing in a box
func (rs *RepoStatus) draw() { func (rs *RepoStatus) draw() {
if ! rs.Ready() {return} if !rs.Ready() {
return
}
// display the status of the git repository // display the status of the git repository
rs.drawGitStatus() rs.drawGitStatus()
@ -109,7 +111,7 @@ func (rs *RepoStatus) drawGitCommands() {
log.Warn("something went wrong switching to the master branch. full stop!") log.Warn("something went wrong switching to the master branch. full stop!")
return return
} }
if ! rs.runGitCommands() { if !rs.runGitCommands() {
log.Warn("SOMETHING WENT WRONG") log.Warn("SOMETHING WENT WRONG")
return return
} }
@ -118,17 +120,17 @@ func (rs *RepoStatus) drawGitCommands() {
}) })
rs.major = gadgets.NewBasicCombobox(newgrid, "major") rs.major = gadgets.NewBasicCombobox(newgrid, "major")
rs.major.Custom = func () { rs.major.Custom = func() {
rs.setTag() rs.setTag()
rs.generateCmd() rs.generateCmd()
} }
rs.minor = gadgets.NewBasicCombobox(newgrid, "minor") rs.minor = gadgets.NewBasicCombobox(newgrid, "minor")
rs.minor.Custom = func () { rs.minor.Custom = func() {
rs.setTag() rs.setTag()
rs.generateCmd() rs.generateCmd()
} }
rs.revision = gadgets.NewBasicCombobox(newgrid, "revision") rs.revision = gadgets.NewBasicCombobox(newgrid, "revision")
rs.revision.Custom = func () { rs.revision.Custom = func() {
rs.setTag() rs.setTag()
rs.generateCmd() rs.generateCmd()
} }
@ -136,19 +138,19 @@ func (rs *RepoStatus) drawGitCommands() {
rs.newversion = newgrid.NewLabel("3.1.4") rs.newversion = newgrid.NewLabel("3.1.4")
rs.versionMessage = gadgets.NewBasicEntry(newgrid, "tag message") rs.versionMessage = gadgets.NewBasicEntry(newgrid, "tag message")
rs.versionMessage.Custom = func () { rs.versionMessage.Custom = func() {
rs.generateCmd() rs.generateCmd()
} }
rs.versionCmdOutput = gadgets.NewOneLiner(newgrid, "tag cmd") rs.versionCmdOutput = gadgets.NewOneLiner(newgrid, "tag cmd")
rs.releaseVersion = newgrid.NewButton("tag and release new version", func() { 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") log.Warn("something is wrong. fix the errors first")
return return
} }
rs.releaseVersion.Disable() rs.releaseVersion.Disable()
log.Warn("COMMIT IT HERE") log.Warn("COMMIT IT HERE")
if ! rs.runGitCommands() { if !rs.runGitCommands() {
log.Warn("SOMETHING WENT WRONG") log.Warn("SOMETHING WENT WRONG")
} }
rs.Update() rs.Update()
@ -280,7 +282,7 @@ func (rs *RepoStatus) generateCmd() bool {
// or something the users might see. // or something the users might see.
// aka: "Topsy", "Picasso", "Buzz", etc // aka: "Topsy", "Picasso", "Buzz", etc
if ! rs.setTag() { if !rs.setTag() {
log.Warn("tag sucked. fix your tag version") log.Warn("tag sucked. fix your tag version")
rs.versionMessage.SetLabel("tag message (bad version)") rs.versionMessage.SetLabel("tag message (bad version)")
rs.releaseVersion.Disable() rs.releaseVersion.Disable()
@ -328,7 +330,7 @@ func (rs *RepoStatus) setGitCommands() {
var all [][]string var all [][]string
newTag := rs.newversion.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) all = append(all, line1)
line2 = append(line2, "git", "push", "--tags") line2 = append(line2, "git", "push", "--tags")
all = append(all, line2) all = append(all, line2)

8
git.go
View File

@ -4,8 +4,8 @@ import (
"strings" "strings"
"unicode/utf8" "unicode/utf8"
"io/ioutil"
"go.wit.com/log" "go.wit.com/log"
"io/ioutil"
) )
func (rs *RepoStatus) GetPath() string { 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) log.Warn("checkoutBranch() checkDirty() == true for repo", rs.repopath, "looking for branch:", branch)
return return
} }
out := run(rs.repopath, "git", "checkout " + branch) out := run(rs.repopath, "git", "checkout "+branch)
log.Warn(rs.repopath, "git checkout " + branch, "returned", out) log.Warn(rs.repopath, "git checkout "+branch, "returned", out)
realname := rs.getCurrentBranchName() realname := rs.getCurrentBranchName()
realversion := rs.getCurrentBranchVersion() realversion := rs.getCurrentBranchVersion()
@ -232,7 +232,7 @@ func (rs *RepoStatus) CheckBranches() bool {
} }
var cmd []string var cmd []string
cmd = append(cmd, "git", "show", "-s", "--format=%ci", hash) 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 // git show -s --format=%ci <hash> will give you the time
// log.Warn(fullfile) // log.Warn(fullfile)
if hash == hashCheck { if hash == hashCheck {

8
new.go
View File

@ -1,20 +1,20 @@
package repostatus package repostatus
import ( import (
"go.wit.com/log"
"go.wit.com/gui/gui" "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 { func New(p *gui.Node, path string) *RepoStatus {
rs := &RepoStatus { rs := &RepoStatus{
hidden: true, hidden: true,
ready: false, ready: false,
parent: p, parent: p,
repopath: path, repopath: path,
} }
rs.tags = make(map[string]string) 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.Horizontal()
rs.window.Make() rs.window.Make()
rs.ready = true rs.ready = true

View File

@ -2,7 +2,7 @@ package repostatus
import ( import (
"go.wit.com/gui/gui" "go.wit.com/gui/gui"
"go.wit.com/gui/gadgets" "go.wit.com/lib/gadgets"
) )
type RepoStatus struct { type RepoStatus struct {
@ -20,7 +20,7 @@ type RepoStatus struct {
// group *gui.Node // group *gui.Node
// grid *gui.Node // grid *gui.Node
// status *gadgets.OneLiner // status *gadgets.OneLiner
dirtyLabel *gadgets.OneLiner dirtyLabel *gadgets.OneLiner
path *gadgets.OneLiner path *gadgets.OneLiner
@ -36,7 +36,7 @@ type RepoStatus struct {
develMerge *gui.Node develMerge *gui.Node
releaseVersion *gui.Node releaseVersion *gui.Node
// vgroup *gui.Node // vgroup *gui.Node
minor *gadgets.BasicCombobox minor *gadgets.BasicCombobox
major *gadgets.BasicCombobox major *gadgets.BasicCombobox
revision *gadgets.BasicCombobox revision *gadgets.BasicCombobox

View File

@ -12,6 +12,8 @@ func timeFunction(f func()) time.Duration {
} }
func (ls *RepoStatus) SetSpeedActual(s string) { func (ls *RepoStatus) SetSpeedActual(s string) {
if ! ls.Ready() {return} if !ls.Ready() {
return
}
ls.speedActual.SetText(s) ls.speedActual.SetText(s)
} }

14
unix.go
View File

@ -2,13 +2,13 @@
package repostatus package repostatus
import ( import (
"errors"
"os" "os"
"os/exec" "os/exec"
"os/user" "os/user"
"strings"
"regexp"
"errors"
"path/filepath" "path/filepath"
"regexp"
"strings"
"go.wit.com/log" "go.wit.com/log"
) )
@ -54,8 +54,8 @@ func listFiles(directory string) []string {
dirname := file.Name() dirname := file.Name()
newdir, _ := os.ReadDir(directory + "/" + dirname) newdir, _ := os.ReadDir(directory + "/" + dirname)
for _, file := range newdir { for _, file := range newdir {
if ! file.IsDir() { if !file.IsDir() {
files = append(files, dirname + "/" + file.Name()) files = append(files, dirname+"/"+file.Name())
} }
} }
} else { } else {
@ -91,7 +91,9 @@ func alphaOnly(s string) bool {
func normalizeVersion(s string) string { func normalizeVersion(s string) string {
// reg, err := regexp.Compile("[^a-zA-Z0-9]+") // reg, err := regexp.Compile("[^a-zA-Z0-9]+")
parts := strings.Split(s, "-") parts := strings.Split(s, "-")
if len(parts) == 0 { return "" } if len(parts) == 0 {
return ""
}
reg, err := regexp.Compile("[^0-9.]+") reg, err := regexp.Compile("[^0-9.]+")
if err != nil { if err != nil {
log.Log(WARN, "normalizeVersion() regexp.Compile() ERROR =", err) log.Log(WARN, "normalizeVersion() regexp.Compile() ERROR =", err)

View File

@ -1,21 +1,21 @@
package repostatus package repostatus
import ( import (
"errors"
"fmt" "fmt"
"time" "time"
"errors"
"go.wit.com/log" "go.wit.com/log"
) )
func (rs *RepoStatus) Update() { func (rs *RepoStatus) Update() {
if ! rs.Ready() { if !rs.Ready() {
log.Log(WARN, "can't update yet. ready is false") log.Log(WARN, "can't update yet. ready is false")
log.Error(errors.New("Update() is not ready yet")) log.Error(errors.New("Update() is not ready yet"))
return return
} }
log.Log(WARN, "Update() START") log.Log(WARN, "Update() START")
duration := timeFunction(func () { duration := timeFunction(func() {
// do things that are safe even if the git tree is dirty // do things that are safe even if the git tree is dirty
log.Warn("path.SetText()") log.Warn("path.SetText()")
rs.path.SetText(rs.repopath) rs.path.SetText(rs.repopath)
@ -67,9 +67,9 @@ func (rs *RepoStatus) setSpeed(duration time.Duration) {
} }
rs.speedActual.SetText(s) rs.speedActual.SetText(s)
if (duration > 500 * time.Millisecond ) { if duration > 500*time.Millisecond {
rs.speed.SetText("SLOW") rs.speed.SetText("SLOW")
} else if (duration > 100 * time.Millisecond ) { } else if duration > 100*time.Millisecond {
rs.speed.SetText("OK") rs.speed.SetText("OK")
} else { } else {
rs.speed.SetText("FAST") rs.speed.SetText("FAST")