Skip to content

Commit f577c72

Browse files
committed
wire up the tag cmd call
1 parent 3d5a70e commit f577c72

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

client/repos_tag.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ package client
33
import (
44
"bytes"
55
"context"
6+
"fmt"
67
"os/exec"
78
"strings"
9+
10+
"github.com/gosuri/uiprogress"
811
)
912

1013
func (c *Client) ListTags(ctx context.Context, dirs []string, args ...string) error {
@@ -43,5 +46,66 @@ func (c *Client) ListTags(ctx context.Context, dirs []string, args ...string) er
4346
}
4447

4548
func (c *Client) TagRepos(ctx context.Context, dirs []string, args ...string) error {
49+
count := len(dirs)
50+
args = append([]string{"tag"}, args...)
51+
52+
verbose := Verbose(ctx)
53+
54+
var bar *uiprogress.Bar
55+
currRepo := ""
56+
57+
if verbose {
58+
c.scrb.BeginDescribe("Command")
59+
defer c.scrb.EndDescribe()
60+
61+
c.scrb.Print(fmt.Sprintf("git %s", strings.Join(args, " ")))
62+
63+
c.scrb.BeginDescribe("directories")
64+
defer c.scrb.EndDescribe()
65+
} else {
66+
bar = uiprogress.AddBar(count).
67+
AppendCompleted().
68+
PrependElapsed().
69+
PrependFunc(func(b *uiprogress.Bar) string {
70+
return fmt.Sprintf("Tagging (%d/%d)", b.Current(), count)
71+
}).
72+
AppendFunc(func(b *uiprogress.Bar) string {
73+
return currRepo
74+
})
75+
}
76+
77+
for _, dir := range dirs {
78+
currRepo = fmt.Sprintf("\nCurrent Repo: %v", dir)
79+
80+
out := &bytes.Buffer{}
81+
errout := &bytes.Buffer{}
82+
83+
cmd := exec.CommandContext(ctx, "git", args...)
84+
cmd.Stdout = out
85+
cmd.Stderr = errout
86+
cmd.Dir = dir
87+
88+
err := cmd.Run()
89+
if err != nil && !verbose {
90+
return fmt.Errorf("tag repo: %w", err) // TODO: collect errors and return them all
91+
}
92+
93+
if verbose {
94+
c.scrb.BeginDescribe(dir)
95+
if err != nil {
96+
c.scrb.Error(err)
97+
c.scrb.PrintLines(errout)
98+
} else {
99+
c.scrb.PrintLines(out)
100+
}
101+
102+
c.scrb.EndDescribe()
103+
} else {
104+
bar.Incr()
105+
}
106+
}
107+
108+
currRepo = ""
109+
46110
return nil
47111
}

0 commit comments

Comments
 (0)