From 009d8f3b9d743fb1fa891376d5c36290681e33f1 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 13 Nov 2024 10:33:25 -0600 Subject: [PATCH] improve output handling via go-cmd Signed-off-by: Jeff Carr --- common.go | 5 +++-- git.go | 11 ++++++----- tagWindow.go | 3 ++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/common.go b/common.go index c6d8995..74f57f4 100644 --- a/common.go +++ b/common.go @@ -8,7 +8,7 @@ import ( "unicode" "go.wit.com/log" - // "go.wit.com/gui/gui" + "go.wit.com/lib/gui/shell" ) // reports externally if something has changed @@ -164,7 +164,8 @@ func (rs *RepoStatus) RepoType() string { return "" } os.Setenv("GO111MODULE", "off") - r := rs.Run([]string{"go", "list", "-f", "'{{if eq .Name \"main\"}}binary{{else}}library{{end}}'"}) + cmd := []string{"go", "list", "-f", "'{{if eq .Name \"main\"}}binary{{else}}library{{end}}'"} + r := shell.PathRunLog(rs.Path(), cmd, INFO) output := strings.TrimSpace(strings.Join(r.Stdout, "\n")) if r.Error != nil { log.Info("go package error:", r.Error) diff --git a/git.go b/git.go index a921ef2..e87860e 100644 --- a/git.go +++ b/git.go @@ -11,6 +11,7 @@ import ( "io/ioutil" "go.wit.com/log" + "go.wit.com/lib/gui/shell" ) func (rs *RepoStatus) GetCurrentBranchName() string { @@ -95,7 +96,7 @@ func (rs *RepoStatus) gitDescribeByHash(hash string) (string, error) { if hash == "" { return "", errors.New("hash was blank") } - r := rs.Run([]string{"git", "describe", "--tags", "--always", hash}) + r := shell.PathRunLog(rs.Path(), []string{"git", "describe", "--tags", "--always", hash}, INFO) out := strings.Join(r.Stdout, "\n") if r.Error != nil { log.Warn("not in a git repo or bad hash?", r.Error, rs.Path()) @@ -109,7 +110,7 @@ func (rs *RepoStatus) gitDescribeByName(name string) (string, error) { if name == "" { // git will return the current tag - r := rs.Run([]string{"git", "describe", "--tags", "--always"}) + r := shell.PathRunLog(rs.Path(), []string{"git", "describe", "--tags", "--always"}, INFO) output := strings.Join(r.Stdout, "\n") if r.Error != nil { log.Warn("gitDescribeByName() not in a git repo?", r.Error, rs.Path()) @@ -121,7 +122,7 @@ func (rs *RepoStatus) gitDescribeByName(name string) (string, error) { return "", errors.New("gitDescribeByName() git fatal: Not a valid object name") } cmd := []string{"git", "describe", "--tags", "--always", name} - r := rs.Run(cmd) + r := shell.PathRunLog(rs.Path(), cmd, INFO) output := strings.Join(r.Stdout, "\n") if r.Error != nil { log.Warn("cmd =", cmd) @@ -211,7 +212,7 @@ func (rs *RepoStatus) DirtyList() []string { func (rs *RepoStatus) CheckDirty() bool { var start string = rs.dirtyLabel.String() cmd := []string{"git", "status", "--porcelain"} - r := rs.Run(cmd) + r := shell.PathRunLog(rs.Path(), cmd, INFO) out := strings.Join(r.Stdout, "\n") if r.Error != nil { log.Warn("CheckDirty() status cmd =", cmd) @@ -571,7 +572,7 @@ func (rs *RepoStatus) CheckBranches() bool { } var cmd []string cmd = append(cmd, "git", "show", "-s", "--format=%ci", hash) - r := rs.Run(cmd) + r := shell.PathRunLog(rs.Path(), cmd, INFO) if r.Error != nil { log.Log(WARN, "CheckBranches() git show error:", r.Error) } diff --git a/tagWindow.go b/tagWindow.go index 4f0efbc..59caef5 100644 --- a/tagWindow.go +++ b/tagWindow.go @@ -10,6 +10,7 @@ import ( "time" "go.wit.com/gui" + "go.wit.com/lib/gui/shell" "go.wit.com/log" ) @@ -99,7 +100,7 @@ func (rs *RepoStatus) makeTagBox(box *gui.Node) error { format := strings.Join(tags, "_,,,_") cmd := []string{"git", "for-each-ref", "--sort=taggerdate", "--format", format} // log.Info("RUNNING:", strings.Join(cmd, " ")) - r := rs.Run(cmd) + r := shell.PathRunQuiet(rs.Path(), cmd) if r.Error != nil { log.Warn("git for-each-ref error:", r.Error) return r.Error