-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
# Conflicts: # go.mod
- Loading branch information
Showing
9 changed files
with
411 additions
and
208 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
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.