Skip to content

Commit

Permalink
Some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
roblaszczak committed Jan 16, 2022
1 parent 41ac542 commit b45599c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
5 changes: 1 addition & 4 deletions trainings/config/training.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/afero"

"github.com/ThreeDotsLabs/cli/internal"
)

const trainingConfigFile = ".tdl-training"
Expand Down Expand Up @@ -40,8 +38,7 @@ func (c Config) TrainingConfig(trainingRootFs afero.Fs) TrainingConfig {
return config
}

// todo - check if it's printing properly
var TrainingRootNotFoundError = errors.Errorf("training root not found, did you run %s?", internal.SprintCommand("tdl trainings init"))
var TrainingRootNotFoundError = errors.Errorf("training root not found")

func (c Config) FindTrainingRoot() (string, error) {
wd, err := os.Getwd()
Expand Down
4 changes: 1 addition & 3 deletions trainings/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/ThreeDotsLabs/cli/internal"
"github.com/ThreeDotsLabs/cli/trainings/config"
"github.com/ThreeDotsLabs/cli/trainings/web"
)

func (h *Handlers) Info(ctx context.Context) error {
trainingRoot, err := h.config.FindTrainingRoot()
if errors.Is(err, config.TrainingRootNotFoundError) {
fmt.Println("You are not in a training directory. If you already started the training, please go to the exercise directory.")
fmt.Printf("Please run %s if you didn't start training yet.\n", internal.SprintCommand("tdl training init"))
h.printNotInATrainingDirectory()
return nil
}

Expand Down
20 changes: 4 additions & 16 deletions trainings/next.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package trainings

import (
"context"
"fmt"

"github.com/fatih/color"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
Expand All @@ -13,7 +11,6 @@ import (

"github.com/ThreeDotsLabs/cli/trainings/files"

"github.com/ThreeDotsLabs/cli/internal"
"github.com/ThreeDotsLabs/cli/trainings/config"
"github.com/ThreeDotsLabs/cli/trainings/genproto"
)
Expand All @@ -36,15 +33,17 @@ func (h *Handlers) nextExercise(ctx context.Context, currentExerciseID string) e
return err
}
if finished {
trainingFinished()
printFinished()
return nil
}

if err := h.writeExerciseFiles(resp, trainingRootFs); err != nil {
return err
}

return h.showExerciseTips()
h.printExerciseTips()

return nil
}

func (h *Handlers) getNextExercise(ctx context.Context, currentExerciseID string, trainingRootFs afero.Fs) (finished bool, resp *genproto.NextExerciseResponse, err error) {
Expand Down Expand Up @@ -77,14 +76,3 @@ func (h *Handlers) writeExerciseFiles(resp *genproto.NextExerciseResponse, train
},
)
}

func (h *Handlers) showExerciseTips() error {
fmt.Printf("To run solution, please execute " + internal.SprintCommand("tdl training run"))
fmt.Println()

return nil
}

func trainingFinished() {
fmt.Println("Congratulations, you finished the training " + color.YellowString("🏆"))
}
22 changes: 22 additions & 0 deletions trainings/print.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package trainings

import (
"fmt"

"github.com/ThreeDotsLabs/cli/internal"
"github.com/fatih/color"
)

func (h *Handlers) printNotInATrainingDirectory() {
fmt.Println("You are not in a training directory. If you already started the training, please go to the exercise directory.")
fmt.Printf("Please run %s if you didn't start training yet.\n", internal.SprintCommand("tdl training init"))
}

func (h *Handlers) printExerciseTips() {
fmt.Printf("To run solution, please execute " + internal.SprintCommand("tdl training run"))
fmt.Println()
}

func printFinished() {
fmt.Println("Congratulations, you finished the training " + color.YellowString("🏆"))
}
3 changes: 1 addition & 2 deletions trainings/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import (
func (h *Handlers) Run(ctx context.Context) (bool, error) {
trainingRoot, err := h.config.FindTrainingRoot()
if errors.Is(err, config.TrainingRootNotFoundError) {
fmt.Println("You are not in a training directory. If you already started the training, please go to the exercise directory.")
fmt.Printf("Please run %s if you didn't start training yet.\n", internal.SprintCommand("tdl training init"))
h.printNotInATrainingDirectory()
return false, nil
}

Expand Down

0 comments on commit b45599c

Please sign in to comment.