-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ThreeDotsLabs/added-tdl-clone
Added tdl clone
- Loading branch information
Showing
9 changed files
with
412 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
module github.com/ThreeDotsLabs/cli | ||
|
||
go 1.17 | ||
go 1.20 | ||
|
||
require ( | ||
github.com/BurntSushi/toml v0.4.1 | ||
github.com/fatih/color v1.12.0 | ||
github.com/golang/protobuf v1.5.2 | ||
github.com/golang/protobuf v1.5.3 | ||
github.com/hexops/gotextdiff v1.0.3 | ||
github.com/pkg/errors v0.9.1 | ||
github.com/sirupsen/logrus v1.8.1 | ||
github.com/spf13/afero v1.6.0 | ||
github.com/stretchr/testify v1.7.0 | ||
github.com/stretchr/testify v1.8.4 | ||
github.com/urfave/cli/v2 v2.3.0 | ||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 | ||
google.golang.org/grpc v1.40.0 | ||
google.golang.org/protobuf v1.27.1 | ||
golang.org/x/crypto v0.18.0 | ||
google.golang.org/grpc v1.60.1 | ||
google.golang.org/protobuf v1.32.0 | ||
) | ||
|
||
require ( | ||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/google/go-cmp v0.6.0 // indirect | ||
github.com/kr/pretty v0.3.0 // indirect | ||
github.com/mattn/go-colorable v0.1.8 // indirect | ||
github.com/mattn/go-isatty v0.0.12 // indirect | ||
github.com/mattn/go-isatty v0.0.17 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rogpeppe/go-internal v1.9.0 // indirect | ||
github.com/russross/blackfriday/v2 v2.0.1 // indirect | ||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect | ||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect | ||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect | ||
golang.org/x/text v0.3.5 // indirect | ||
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect | ||
golang.org/x/net v0.20.0 // indirect | ||
golang.org/x/sys v0.16.0 // indirect | ||
golang.org/x/term v0.16.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect | ||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package trainings | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/ThreeDotsLabs/cli/trainings/config" | ||
"github.com/ThreeDotsLabs/cli/trainings/genproto" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/afero" | ||
) | ||
|
||
func (h *Handlers) Clone(ctx context.Context, executionID string) error { | ||
pwd, err := os.Getwd() | ||
if err != nil { | ||
return fmt.Errorf("failed to get current working directory: %w", err) | ||
} | ||
|
||
resp, err := h.newGrpcClient(ctx).GetSolutionFiles(ctx, &genproto.GetSolutionFilesRequest{ | ||
ExecutionId: executionID, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("failed to get solution files: %w", err) | ||
} | ||
|
||
logrus.WithFields(logrus.Fields{ | ||
"resp": resp, | ||
"err": err, | ||
}).Debug("Received exercise from server") | ||
|
||
if err := h.startTraining(ctx, resp.TrainingName); err != nil { | ||
return err | ||
} | ||
|
||
trainingRootFs := afero.NewBasePathFs(afero.NewOsFs(), pwd).(*afero.BasePathFs) | ||
|
||
if err := h.config.WriteTrainingConfig(config.TrainingConfig{TrainingName: resp.TrainingName}, trainingRootFs); err != nil { | ||
return errors.Wrap(err, "can't write training config") | ||
} | ||
|
||
files := &genproto.NextExerciseResponse{ | ||
TrainingStatus: genproto.NextExerciseResponse_IN_PROGRESS, | ||
Dir: resp.Dir, | ||
ExerciseId: resp.ExerciseId, | ||
FilesToCreate: resp.FilesToCreate, | ||
IsTextOnly: false, | ||
} | ||
|
||
if err := h.writeExerciseFiles(files, trainingRootFs); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.