Skip to content

Commit 627d4cf

Browse files
committed
enable cloning to a dir
1 parent 5536cb9 commit 627d4cf

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

client/clienter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
type Clienter interface {
1010
Add(ctx context.Context, dirs []string, name, baseURL string) error
1111
CheckoutRepos(ctx context.Context, repoDirs []string, args ...string) error
12-
CloneRepos(ctx context.Context) ([]*Repository, error)
12+
CloneRepos(ctx context.Context, dir string) ([]*Repository, error)
1313
GetDirs(ctx context.Context, dir string) ([]string, error)
1414
GetLogins(ctx context.Context) ([]string, error)
1515
GetRepos(ctx context.Context, name string) ([]*github.Repository, error)

client/repos_clone.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/gosuri/uiprogress"
1212
)
1313

14-
func (c *Client) CloneRepos(ctx context.Context) ([]*Repository, error) {
14+
func (c *Client) CloneRepos(ctx context.Context, baseDir string) ([]*Repository, error) {
1515
dirRepos, err := RepoMap(ctx)
1616
if err != nil {
1717
return nil, fmt.Errorf("repomap context: %w", err)
@@ -41,6 +41,10 @@ func (c *Client) CloneRepos(ctx context.Context) ([]*Repository, error) {
4141
cloned := []*Repository{}
4242
var errs error
4343
for dir, rs := range dirRepos {
44+
if baseDir != "" {
45+
dir = baseDir
46+
}
47+
4448
for i := range rs {
4549
currRepo = fmt.Sprintf("\nCurrent Repo: %v/%v", dir, rs[i].name)
4650
dest := path.Join(".", dir, rs[i].name)

client/testclient/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (c *TestClient) CheckoutRepos(ctx context.Context, repoDirs []string, args
2121
return nil
2222
}
2323

24-
func (c *TestClient) CloneRepos(ctx context.Context) ([]*client.Repository, error) {
24+
func (c *TestClient) CloneRepos(ctx context.Context, baseDir string) ([]*client.Repository, error) {
2525
c.CommandsCalled = append(c.CommandsCalled, "CloneRepos")
2626

2727
return nil, nil

cmd/clone.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212

1313
func init() {
1414
RootCmd.AddCommand(cloneCmd)
15+
16+
cloneCmd.Flags().StringVar(&dir, "dir", ".", "directory to clone repos into")
1517
}
1618

1719
var cloneCmd = &cobra.Command{
@@ -46,7 +48,7 @@ func cloneFunc(cmd *cobra.Command, args []string) error {
4648

4749
ctx = client.WithRepos(ctx, repos)
4850

49-
_, err = clt.CloneRepos(ctx)
51+
_, err = clt.CloneRepos(ctx, dir)
5052
if err != nil {
5153
cmd.SilenceUsage = true
5254
return fmt.Errorf("clone repos: %w", err)

0 commit comments

Comments
 (0)