use go-cmd/cmd

This commit is contained in:
Jeff Carr 2024-11-08 06:43:45 -06:00
parent ca00923762
commit 29551667f0
8 changed files with 43 additions and 39 deletions

View File

@ -6,6 +6,7 @@ import (
"path/filepath" "path/filepath"
"sort" "sort"
"github.com/go-cmd/cmd"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gui/repostatus" "go.wit.com/lib/gui/repostatus"
"go.wit.com/log" "go.wit.com/log"
@ -110,8 +111,8 @@ func (r *RepoRow) IsPerfect() bool {
return false return false
} }
func (r *RepoRow) RunCmd(cmd []string) (error, string) { func (r *RepoRow) Run(cmd []string) cmd.Status {
return r.Status.RunCmd(cmd) return r.Status.Run(cmd)
} }
func (r *RepoRow) AllTags() []*repostatus.Tag { func (r *RepoRow) AllTags() []*repostatus.Tag {

View File

@ -28,15 +28,15 @@ func (repo *RepoRow) GetPatches(oldname string, newname string) (int, []*Patch)
// log.Info("repo userv, develv", userv, develv) // log.Info("repo userv, develv", userv, develv)
gitcmd := []string{"git", "log", "--oneline", oldname + ".." + newname} gitcmd := []string{"git", "log", "--oneline", oldname + ".." + newname}
log.Info("Run:", gitcmd) log.Info("Run:", gitcmd)
err, output := repo.Status.RunCmd(gitcmd) r := repo.Status.Run(gitcmd)
if err != nil { if r.Error != nil {
log.Info("git failed ", repo.GoPath(), "err =", err) log.Info("git failed ", repo.GoPath(), "err =", r.Error)
return 0, nil return 0, nil
} }
// patches = strings.Split(output, "\n") // patches = strings.Split(output, "\n")
log.Info("Run:", output) log.Info("Run:", r.Stdout)
for _, line := range strings.Split(output, "\n") { for _, line := range r.Stdout {
line = strings.TrimSpace(line) line = strings.TrimSpace(line)
if line == "" { if line == "" {
continue continue
@ -98,9 +98,9 @@ func (r *RepoList) MakePatchset(setdir string) bool {
// git format-patch branch1..branch2 // git format-patch branch1..branch2
gitcmd := []string{"git", "format-patch", "-o", repodir, develn + ".." + usern} gitcmd := []string{"git", "format-patch", "-o", repodir, develn + ".." + usern}
log.Info("Run:", gitcmd) log.Info("Run:", gitcmd)
err, output := repo.Status.RunCmd(gitcmd) r := repo.Status.Run(gitcmd)
log.Info("output =", output) log.Info("output =", r.Stdout)
if err == nil { if r.Error == nil {
log.Info("patches made okay for:", repo.GoPath()) log.Info("patches made okay for:", repo.GoPath())
continue continue
} }

View File

@ -23,9 +23,9 @@ func (r *RepoRow) StandardHeader() string {
user := r.Status.GetUserVersion() user := r.Status.GetUserVersion()
header := fmt.Sprintf("%-35s %5s %-10s %-10s %-20s %-20s %-20s %-15s", header := fmt.Sprintf("%-35s %5s %-10s %-10s %-20s %-20s %-20s %-15s",
r.Name(), shell.FormatDuration(dur), r.Name(), shell.FormatDuration(dur),
lastTag, target, lastTag, target,
master, devel, user, master, devel, user,
r.State()) r.State())
return header return header
} }
@ -51,14 +51,14 @@ func (v *RepoList) PrintReport(readonly string, onlydirty string, perfect string
header := repo.StandardHeader() header := repo.StandardHeader()
if onlydirty == "true" { if onlydirty == "true" {
if repo.CheckDirty() { if repo.CheckDirty() {
log.Info(header+"") log.Info(header + "")
} }
continue continue
} }
if repo.ReadOnly() { if repo.ReadOnly() {
if readonly == "true" { if readonly == "true" {
log.Info(header+"readonly") log.Info(header + "readonly")
} }
continue continue
} }
@ -68,14 +68,14 @@ func (v *RepoList) PrintReport(readonly string, onlydirty string, perfect string
} }
} }
if repo.State() != "merge to main" { if repo.State() != "merge to main" {
log.Info(header+"") log.Info(header + "")
continue continue
} }
if repo.CheckDirty() { if repo.CheckDirty() {
log.Info(header+"") log.Info(header + "")
continue continue
} }
log.Info(header+"") log.Info(header + "")
} }
log.Info(fmt.Sprintf("EVERYTHING WORKED repo count = %d", count)) log.Info(fmt.Sprintf("EVERYTHING WORKED repo count = %d", count))
} }

View File

@ -6,6 +6,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"go.wit.com/lib/protobuf/virtbuf" "go.wit.com/lib/protobuf/virtbuf"
) )
@ -45,10 +46,10 @@ func (m *ViewRepoManager) Start(ctx context.Context, cluster *virtbuf.Cluster) e
return errors.New("cluster cannot be nil") return errors.New("cluster cannot be nil")
} }
/* /*
err := m.client.StartRepo(ctx, cluster.Id) err := m.client.StartRepo(ctx, cluster.Id)
if err != nil { if err != nil {
return fmt.Errorf("error starting cluster %q: %w", cluster.Id, err) return fmt.Errorf("error starting cluster %q: %w", cluster.Id, err)
} }
*/ */
return nil return nil
} }
@ -59,10 +60,10 @@ func (m *ViewRepoManager) Stop(ctx context.Context, cluster *virtbuf.Cluster) er
return errors.New("cluster cannot be nil") return errors.New("cluster cannot be nil")
} }
/* /*
err := m.client.StopRepo(ctx, cluster.Id) err := m.client.StopRepo(ctx, cluster.Id)
if err != nil { if err != nil {
return fmt.Errorf("error stopping cluster %q: %w", cluster.Id, err) return fmt.Errorf("error stopping cluster %q: %w", cluster.Id, err)
} }
*/ */
return nil return nil
} }
@ -70,11 +71,11 @@ func (m *ViewRepoManager) Stop(ctx context.Context, cluster *virtbuf.Cluster) er
// List retrieves all available clusters. // List retrieves all available clusters.
func (m *ViewRepoManager) List(ctx context.Context) ([]*virtbuf.Cluster, error) { func (m *ViewRepoManager) List(ctx context.Context) ([]*virtbuf.Cluster, error) {
/* /*
clusters, err := m.client.ListRepos(ctx) clusters, err := m.client.ListRepos(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("error listing clusters: %w", err) return nil, fmt.Errorf("error listing clusters: %w", err)
} }
return clusters, nil return clusters, nil
*/ */
return nil, errors.New("List not done yet") return nil, errors.New("List not done yet")
} }
@ -85,10 +86,10 @@ func (m *ViewRepoManager) Status(ctx context.Context, cluster *virtbuf.Cluster)
return "", errors.New("cluster cannot be nil") return "", errors.New("cluster cannot be nil")
} }
/* /*
status, err := m.client.GetRepoStatus(ctx, cluster.Id) status, err := m.client.GetRepoStatus(ctx, cluster.Id)
if err != nil { if err != nil {
return "", fmt.Errorf("error getting status of cluster %q: %w", cluster.Id, err) return "", fmt.Errorf("error getting status of cluster %q: %w", cluster.Id, err)
} }
*/ */
return "", nil return "", nil
} }

View File

@ -138,14 +138,14 @@ func (r *RepoList) makeAutotypistView(newRepo *RepoRow) {
} }
r.reposbox.Disable() r.reposbox.Disable()
// restore anything staged so everything can be reviewed // restore anything staged so everything can be reviewed
newRepo.Status.RunCmd([]string{"git", "restore", "--staged", "."}) newRepo.Status.Run([]string{"git", "restore", "--staged", "."})
newRepo.Status.XtermWait("git diff") newRepo.Status.XtermWait("git diff")
newRepo.Status.XtermWait("git add --all") newRepo.Status.XtermWait("git add --all")
newRepo.Status.XtermWait("git commit -a") newRepo.Status.XtermWait("git commit -a")
newRepo.Status.XtermWait("git push") newRepo.Status.XtermWait("git push")
if newRepo.Status.CheckDirty() { if newRepo.Status.CheckDirty() {
// commit was not done, restore diff // commit was not done, restore diff
newRepo.Status.RunCmd([]string{"git", "restore", "--staged", "."}) newRepo.Status.Run([]string{"git", "restore", "--staged", "."})
} else { } else {
newRepo.NewScan() newRepo.NewScan()
} }

View File

@ -106,6 +106,8 @@ func (r *RepoList) selectRepoAll() []*RepoRow {
return repoPointers return repoPointers
} }
// this sort doesn't really work. I think it forgets to sort the last two
// todo: sort this out. literally
// SelectRepoPointers safely returns a slice of pointers to Repo records. // SelectRepoPointers safely returns a slice of pointers to Repo records.
func (r *RepoList) selectUnmergedRepos() []*RepoRow { func (r *RepoList) selectUnmergedRepos() []*RepoRow {
r.RLock() r.RLock()

View File

@ -38,7 +38,7 @@ type RepoList struct {
hideFunction func(*RepoRow) hideFunction func(*RepoRow)
duration *gui.Node duration *gui.Node
rows []*RepoRow rows []*RepoRow
} }
type RepoRow struct { type RepoRow struct {

View File

@ -76,14 +76,14 @@ func (r *RepoList) ShowRepo(repo *RepoRow) error {
return return
} }
// restore anything staged so everything can be reviewed // restore anything staged so everything can be reviewed
newRow.Status.RunCmd([]string{"git", "restore", "--staged", "."}) newRow.Status.Run([]string{"git", "restore", "--staged", "."})
newRow.Status.XtermWait("git diff") newRow.Status.XtermWait("git diff")
newRow.Status.XtermWait("git add --all") newRow.Status.XtermWait("git add --all")
newRow.Status.XtermWait("git commit -a") newRow.Status.XtermWait("git commit -a")
newRow.Status.XtermWait("git push") newRow.Status.XtermWait("git push")
if newRow.Status.CheckDirty() { if newRow.Status.CheckDirty() {
// commit was not done, restore diff // commit was not done, restore diff
newRow.Status.RunCmd([]string{"git", "restore", "--staged", "."}) newRow.Status.Run([]string{"git", "restore", "--staged", "."})
} else { } else {
newRow.NewScan() newRow.NewScan()
} }