Skip to content

Commit 7eefdd7

Browse files
authored
Merge pull request #12 from gomicro/pull-tags
move pull dir to be flag based with default and add tags
2 parents d543ccf + b709292 commit 7eefdd7

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

client/repos_checkout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var (
1515
ErrUnstagedChanges = errors.New("unstanged changes")
1616
)
1717

18-
func (c *Client) CheckoutRepos(ctx context.Context, dirs []string, args []string) error {
18+
func (c *Client) CheckoutRepos(ctx context.Context, dirs []string, args ...string) error {
1919
count := len(dirs)
2020
args = append([]string{"checkout"}, args...)
2121

client/repos_pull.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
"github.com/gosuri/uiprogress"
1010
)
1111

12-
func (c *Client) PullRepos(ctx context.Context, dirs []string) error {
12+
func (c *Client) PullRepos(ctx context.Context, dirs []string, args ...string) error {
1313
count := len(dirs)
14+
args = append([]string{"pull"}, args...)
1415

1516
currRepo := ""
1617
bar := uiprogress.AddBar(count).
@@ -26,9 +27,10 @@ func (c *Client) PullRepos(ctx context.Context, dirs []string) error {
2627
for _, dir := range dirs {
2728
currRepo = fmt.Sprintf("\nCurrent Repo: %v", dir)
2829

29-
cmd := exec.CommandContext(ctx, "git", "pull")
30+
cmd := exec.CommandContext(ctx, "git", args...)
3031

3132
buf := bytes.Buffer{}
33+
3234
cmd.Stdout = &buf
3335

3436
cmd.Dir = dir

cmd/checkout.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ import (
88
"github.com/spf13/cobra"
99
)
1010

11+
func init() {
12+
checkoutCmd.Flags().StringVarP(&dir, "dir", "d", ".", "directory to checkout repos from")
13+
}
14+
1115
var checkoutCmd = &cobra.Command{
12-
Use: "checkout [branch] (dir)",
16+
Use: "checkout [branch]",
1317
Short: "checkout the desired branch",
1418
Long: `checkout the desired branch`,
1519
Args: cobra.RangeArgs(1, 2),
@@ -20,11 +24,6 @@ var checkoutCmd = &cobra.Command{
2024
func checkoutFunc(cmd *cobra.Command, args []string) error {
2125
ctx := context.Background()
2226

23-
dir := "."
24-
if len(args) > 1 {
25-
dir = args[1]
26-
}
27-
2827
uiprogress.Start()
2928
defer uiprogress.Stop()
3029

@@ -34,7 +33,7 @@ func checkoutFunc(cmd *cobra.Command, args []string) error {
3433
return fmt.Errorf("get dirs: %w", err)
3534
}
3635

37-
err = clt.CheckoutRepos(ctx, repoDirs, args)
36+
err = clt.CheckoutRepos(ctx, repoDirs, args...)
3837
if err != nil {
3938
cmd.SilenceUsage = true
4039
return fmt.Errorf("checkout repos: %w", err)

cmd/pull.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@ import (
88
"github.com/spf13/cobra"
99
)
1010

11+
var (
12+
dir string
13+
tags bool
14+
)
15+
16+
func init() {
17+
pullCmd.Flags().StringVarP(&dir, "dir", "d", ".", "directory to pull repos from")
18+
pullCmd.Flags().BoolVar(&tags, "tags", false, "pull tags")
19+
}
20+
1121
var pullCmd = &cobra.Command{
12-
Use: "pull [dir]",
22+
Use: "pull",
1323
Short: "Pull all repos in a directory",
1424
Long: `Pull all repos in a directory.`,
15-
Args: cobra.MaximumNArgs(1),
1625
PersistentPreRun: setupClient,
1726
RunE: pullFunc,
1827
}
1928

2029
func pullFunc(cmd *cobra.Command, args []string) error {
2130
ctx := context.Background()
2231

23-
dir := "."
24-
if len(args) > 0 {
25-
dir = args[0]
26-
}
27-
2832
uiprogress.Start()
2933
defer uiprogress.Stop()
3034

@@ -34,7 +38,11 @@ func pullFunc(cmd *cobra.Command, args []string) error {
3438
return fmt.Errorf("get dirs: %w", err)
3539
}
3640

37-
err = clt.PullRepos(ctx, repoDirs)
41+
if tags {
42+
args = append(args, "--tags")
43+
}
44+
45+
err = clt.PullRepos(ctx, repoDirs, args...)
3846
if err != nil {
3947
cmd.SilenceUsage = true
4048
return fmt.Errorf("pull repos: %w", err)

0 commit comments

Comments
 (0)