@@ -5,10 +5,16 @@ import (
55 "errors"
66 "fmt"
77
8- "github.com/ThreeDotsLabs/cli/internal"
98 "github.com/ThreeDotsLabs/cli/trainings/config"
109 "github.com/ThreeDotsLabs/cli/trainings/genproto"
1110 "github.com/fatih/color"
11+ "github.com/manifoldco/promptui"
12+ )
13+
14+ const (
15+ actionSkipAll = "Skip all remaining optional modules"
16+ actionSkipCurrent = "Skip the current module"
17+ actionCancel = "(cancel)"
1218)
1319
1420func (h * Handlers ) Skip (ctx context.Context ) error {
@@ -27,11 +33,11 @@ func (h *Handlers) Skip(ctx context.Context) error {
2733 Token : h .config .GlobalConfig ().Token ,
2834 })
2935 if err != nil {
30- panic ( err )
36+ return err
3137 }
3238
3339 if ! resp .CanSkip {
34- fmt .Println (color .New (color .FgYellow ).Sprint ("You cannot skip this module." ))
40+ fmt .Println (color .New (color .Bold , color . FgYellow ).Sprint ("You cannot skip this module." ))
3541 return nil
3642 }
3743
@@ -44,17 +50,42 @@ func (h *Handlers) Skip(ctx context.Context) error {
4450 - You can always come back to the skipped module later using "tdl training jump".
4551` )
4652
47- if ! internal .ConfirmPromptDefaultYes ("skip the current module" ) {
53+ actions := []string {actionSkipCurrent , actionCancel }
54+
55+ if resp .CanSkipAllOptional {
56+ actions = append ([]string {actionSkipAll }, actions ... )
57+
58+ fmt .Println (color .New (color .Bold , color .FgYellow ).Sprint ("\n You can also skip all the remaining optional modules in this training." ))
59+ fmt .Printf ("It will let you get the certificate now and you can always come back to the skipped modules later.\n \n " )
60+ }
61+
62+ moduleSelect := promptui.Select {
63+ Label : "Choose what to do" ,
64+ Items : actions ,
65+ Templates : & promptui.SelectTemplates {
66+ Label : "{{ . }}" ,
67+ Active : "{{ . | cyan }}" ,
68+ Inactive : "{{ . }}" ,
69+ },
70+ HideSelected : true ,
71+ }
72+
73+ _ , choice , err := moduleSelect .Run ()
74+ if err != nil {
4875 fmt .Println ("Skipping cancelled" )
49- return nil
76+ return err
5077 }
5178
5279 var skipAll bool
53- if resp .CanSkipAllOptional {
54- fmt .Println ("You can also skip all the remaining optional modules in this training." )
55- fmt .Printf ("It will let you get the certificate now and you can always come back to the skipped modules later using \" tdl training jump\" .\n \n " )
56-
57- skipAll = internal .ConfirmPromptDefaultYes ("skip all the remaining optional modules in this training" )
80+ if choice == actionSkipAll {
81+ fmt .Println ("Skipping all remaining optional modules." )
82+ skipAll = true
83+ } else if choice == actionSkipCurrent {
84+ fmt .Println ("Skipping current module." )
85+ skipAll = false
86+ } else {
87+ fmt .Println ("Skipping cancelled" )
88+ return nil
5889 }
5990
6091 _ , err = h .newGrpcClient ().SkipExercise (context .Background (), & genproto.SkipExerciseRequest {
@@ -64,12 +95,12 @@ func (h *Handlers) Skip(ctx context.Context) error {
6495 SkipAllOptional : skipAll ,
6596 })
6697 if err != nil {
67- panic ( err )
98+ return err
6899 }
69100
70101 _ , err = h .nextExercise (ctx , "" , trainingRoot )
71102 if err != nil {
72- panic ( err )
103+ return err
73104 }
74105
75106 return nil
0 commit comments