Skip to content

Commit 0f0e6f7

Browse files
authored
Merge pull request #21 from ThreeDotsLabs/specify-directory-with-clone
specify directory for clone
2 parents cf59ff6 + a06f16a commit 0f0e6f7

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

tdl/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ var app = &cli.App{
191191
Name: "clone",
192192
Usage: "clone solution files to current directory",
193193
ArgsUsage: fmt.Sprintf(
194-
"<executionID from 'Share your solution' at %s>",
194+
"<executionID from 'Share your solution' at %s> [directory, if empty defaults to current directory]",
195195
internal.WebsiteAddress,
196196
),
197197
Action: func(c *cli.Context) error {
@@ -200,7 +200,9 @@ var app = &cli.App{
200200
return missingArgumentError{"Missing executionID argument"}
201201
}
202202

203-
return newHandlers(c).Clone(c.Context, executionID)
203+
directory := c.Args().Get(1)
204+
205+
return newHandlers(c).Clone(c.Context, executionID, directory)
204206
},
205207
},
206208
{

trainings/clone.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"path"
78

89
"github.com/ThreeDotsLabs/cli/trainings/config"
910
"github.com/ThreeDotsLabs/cli/trainings/genproto"
@@ -12,7 +13,7 @@ import (
1213
"github.com/spf13/afero"
1314
)
1415

15-
func (h *Handlers) Clone(ctx context.Context, executionID string) error {
16+
func (h *Handlers) Clone(ctx context.Context, executionID string, directory string) error {
1617
pwd, err := os.Getwd()
1718
if err != nil {
1819
return fmt.Errorf("failed to get current working directory: %w", err)
@@ -30,12 +31,14 @@ func (h *Handlers) Clone(ctx context.Context, executionID string) error {
3031
"err": err,
3132
}).Debug("Received exercise from server")
3233

33-
wd, err := os.Getwd()
34+
absoluteDirToClone, err := os.Getwd()
3435
if err != nil {
3536
return errors.WithStack(err)
3637
}
3738

38-
if _, err := h.startTraining(ctx, resp.TrainingName, wd); err != nil {
39+
absoluteDirToClone = path.Join(absoluteDirToClone, directory)
40+
41+
if _, err := h.startTraining(ctx, resp.TrainingName, absoluteDirToClone); err != nil {
3942
return err
4043
}
4144

0 commit comments

Comments
 (0)