improve output handling via go-cmd

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-13 10:33:25 -06:00
parent 55acea0bd7
commit 009d8f3b9d
3 changed files with 11 additions and 8 deletions

View File

@ -8,7 +8,7 @@ import (
"unicode" "unicode"
"go.wit.com/log" "go.wit.com/log"
// "go.wit.com/gui/gui" "go.wit.com/lib/gui/shell"
) )
// reports externally if something has changed // reports externally if something has changed
@ -164,7 +164,8 @@ func (rs *RepoStatus) RepoType() string {
return "" return ""
} }
os.Setenv("GO111MODULE", "off") 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")) output := strings.TrimSpace(strings.Join(r.Stdout, "\n"))
if r.Error != nil { if r.Error != nil {
log.Info("go package error:", r.Error) log.Info("go package error:", r.Error)

11
git.go
View File

@ -11,6 +11,7 @@ import (
"io/ioutil" "io/ioutil"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/lib/gui/shell"
) )
func (rs *RepoStatus) GetCurrentBranchName() string { func (rs *RepoStatus) GetCurrentBranchName() string {
@ -95,7 +96,7 @@ func (rs *RepoStatus) gitDescribeByHash(hash string) (string, error) {
if hash == "" { if hash == "" {
return "", errors.New("hash was blank") 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") out := strings.Join(r.Stdout, "\n")
if r.Error != nil { if r.Error != nil {
log.Warn("not in a git repo or bad hash?", r.Error, rs.Path()) 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 == "" { if name == "" {
// git will return the current tag // 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") output := strings.Join(r.Stdout, "\n")
if r.Error != nil { if r.Error != nil {
log.Warn("gitDescribeByName() not in a git repo?", r.Error, rs.Path()) 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") return "", errors.New("gitDescribeByName() git fatal: Not a valid object name")
} }
cmd := []string{"git", "describe", "--tags", "--always", 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") output := strings.Join(r.Stdout, "\n")
if r.Error != nil { if r.Error != nil {
log.Warn("cmd =", cmd) log.Warn("cmd =", cmd)
@ -211,7 +212,7 @@ func (rs *RepoStatus) DirtyList() []string {
func (rs *RepoStatus) CheckDirty() bool { func (rs *RepoStatus) CheckDirty() bool {
var start string = rs.dirtyLabel.String() var start string = rs.dirtyLabel.String()
cmd := []string{"git", "status", "--porcelain"} cmd := []string{"git", "status", "--porcelain"}
r := rs.Run(cmd) r := shell.PathRunLog(rs.Path(), cmd, INFO)
out := strings.Join(r.Stdout, "\n") out := strings.Join(r.Stdout, "\n")
if r.Error != nil { if r.Error != nil {
log.Warn("CheckDirty() status cmd =", cmd) log.Warn("CheckDirty() status cmd =", cmd)
@ -571,7 +572,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)
r := rs.Run(cmd) r := shell.PathRunLog(rs.Path(), cmd, INFO)
if r.Error != nil { if r.Error != nil {
log.Log(WARN, "CheckBranches() git show error:", r.Error) log.Log(WARN, "CheckBranches() git show error:", r.Error)
} }

View File

@ -10,6 +10,7 @@ import (
"time" "time"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gui/shell"
"go.wit.com/log" "go.wit.com/log"
) )
@ -99,7 +100,7 @@ func (rs *RepoStatus) makeTagBox(box *gui.Node) error {
format := strings.Join(tags, "_,,,_") format := strings.Join(tags, "_,,,_")
cmd := []string{"git", "for-each-ref", "--sort=taggerdate", "--format", format} cmd := []string{"git", "for-each-ref", "--sort=taggerdate", "--format", format}
// log.Info("RUNNING:", strings.Join(cmd, " ")) // log.Info("RUNNING:", strings.Join(cmd, " "))
r := rs.Run(cmd) r := shell.PathRunQuiet(rs.Path(), cmd)
if r.Error != nil { if r.Error != nil {
log.Warn("git for-each-ref error:", r.Error) log.Warn("git for-each-ref error:", r.Error)
return r.Error return r.Error