From b040170616c7d6248df6947a78fcdf6ed87cfd19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Sm=C3=B3=C5=82ka?= Date: Sat, 24 Feb 2024 16:03:19 +0100 Subject: [PATCH] print --- trainings/clone.go | 5 ++++- trainings/init.go | 23 ++++++++++++++--------- trainings/next.go | 5 ++++- trainings/run.go | 10 +++++++++- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/trainings/clone.go b/trainings/clone.go index 05877ea..a37636e 100644 --- a/trainings/clone.go +++ b/trainings/clone.go @@ -40,7 +40,10 @@ func (h *Handlers) Clone(ctx context.Context, executionID string) error { return errors.Wrap(err, "can't write training config") } - _ = addModuleToWorkspace(pwd, resp.Dir) + err = addModuleToWorkspace(pwd, resp.Dir) + if err != nil { + logrus.WithError(err).Warn("Failed to add module to workspace") + } files := &genproto.NextExerciseResponse{ TrainingStatus: genproto.NextExerciseResponse_IN_PROGRESS, diff --git a/trainings/init.go b/trainings/init.go index 041a380..dd8c0c9 100644 --- a/trainings/init.go +++ b/trainings/init.go @@ -8,16 +8,14 @@ import ( "path" "strings" + "github.com/ThreeDotsLabs/cli/internal" + "github.com/ThreeDotsLabs/cli/trainings/config" "github.com/ThreeDotsLabs/cli/trainings/files" + "github.com/ThreeDotsLabs/cli/trainings/genproto" "github.com/fatih/color" - "github.com/spf13/afero" - "github.com/pkg/errors" "github.com/sirupsen/logrus" - - "github.com/ThreeDotsLabs/cli/internal" - "github.com/ThreeDotsLabs/cli/trainings/config" - "github.com/ThreeDotsLabs/cli/trainings/genproto" + "github.com/spf13/afero" ) func (h *Handlers) Init(ctx context.Context, trainingName string) error { @@ -79,7 +77,10 @@ func (h *Handlers) startTraining(ctx context.Context, trainingName string) error ) } } else { - _ = createGoWorkspace(trainingRoot) + err = createGoWorkspace(trainingRoot) + if err != nil { + logrus.WithError(err).Warn("Could not create go workspace") + } } _, err = h.newGrpcClient(ctx).StartTraining( @@ -132,6 +133,8 @@ func createGoWorkspace(trainingRoot string) error { cmd := exec.Command("go", "work", "init") cmd.Dir = trainingRoot + printlnCommand(".", "go work init") + if err := cmd.Run(); err != nil { return errors.Wrap(err, "can't run go work init") } @@ -149,8 +152,10 @@ func addModuleToWorkspace(trainingRoot string, modulePath string) error { return nil } - cmd := exec.Command("go", "work", "use", ".") - cmd.Dir = path.Join(trainingRoot, modulePath) + cmd := exec.Command("go", "work", "use", modulePath) + cmd.Dir = trainingRoot + + printlnCommand(".", fmt.Sprintf("go work use %v", modulePath)) if err := cmd.Run(); err != nil { return errors.Wrap(err, "can't run go work use") diff --git a/trainings/next.go b/trainings/next.go index 7fc8897..4f0692c 100644 --- a/trainings/next.go +++ b/trainings/next.go @@ -50,7 +50,10 @@ func (h *Handlers) nextExercise(ctx context.Context, currentExerciseID string) ( resp.ExerciseId, ) } else { - _ = addModuleToWorkspace(trainingRoot, resp.Dir) + err = addModuleToWorkspace(trainingRoot, resp.Dir) + if err != nil { + logrus.WithError(err).Warn("Failed to add module to workspace") + } } return false, nil diff --git a/trainings/run.go b/trainings/run.go index f9540f0..0fd39eb 100644 --- a/trainings/run.go +++ b/trainings/run.go @@ -227,7 +227,7 @@ func (h *Handlers) runExercise(ctx context.Context, trainingRootFs *afero.BasePa } if len(response.Command) > 0 { - fmt.Print(color.CyanString(fmt.Sprintf("••• %s ➜ ", terminalPath)) + response.Command) + printCommand(terminalPath, response.Command) } if len(response.Stdout) > 0 { fmt.Print(response.Stdout) @@ -266,6 +266,14 @@ func (h *Handlers) runExercise(ctx context.Context, trainingRootFs *afero.BasePa } } +func printCommand(root string, command string) { + fmt.Print(color.CyanString(fmt.Sprintf("••• %s ➜ ", root)) + command) +} + +func printlnCommand(root string, command string) { + printCommand(root, command+"\n") +} + func (h *Handlers) generateRunTerminalPath(trainingRootFs *afero.BasePathFs) string { exerciseConfig := h.config.ExerciseConfig(trainingRootFs)