Skip to content

Commit 393f215

Browse files
fetch lesson once
1 parent f6beefd commit 393f215

1 file changed

Lines changed: 19 additions & 21 deletions

File tree

cmd/submit.go

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,9 @@ func submissionHandler(cmd *cobra.Command, args []string) error {
4141
cmd.SilenceUsage = true
4242
isSubmit := cmd.Name() == "submit" || forceSubmit
4343

44-
var lesson *api.Lesson
4544
var lessonUUID string
4645
if len(args) > 0 {
4746
lessonUUID = args[0]
48-
fetchedLesson, err := api.FetchLesson(lessonUUID)
49-
if err != nil {
50-
return err
51-
}
52-
action := "Running"
53-
if isSubmit {
54-
action = "Submitting"
55-
}
56-
fmt.Printf(
57-
"%s lesson:\n%d.%d - %s\n",
58-
action,
59-
fetchedLesson.ChapterNumber,
60-
fetchedLesson.LessonNumber,
61-
fetchedLesson.Lesson.Title,
62-
)
63-
lesson = fetchedLesson
6447
} else {
6548
nextLesson, err := api.FetchNextCLILesson()
6649
if err != nil {
@@ -79,11 +62,25 @@ func submissionHandler(cmd *cobra.Command, args []string) error {
7962
fmt.Printf("Running next lesson:\n%s\n", lessonLabel)
8063
}
8164
lessonUUID = nextLesson.LessonUUID
82-
fetchedLesson, err := api.FetchLesson(lessonUUID)
83-
if err != nil {
84-
return err
65+
}
66+
67+
lesson, err := api.FetchLesson(lessonUUID)
68+
if err != nil {
69+
return err
70+
}
71+
72+
if len(args) > 0 {
73+
action := "Running"
74+
if isSubmit {
75+
action = "Submitting"
8576
}
86-
lesson = fetchedLesson
77+
fmt.Printf(
78+
"%s lesson:\n%d.%d - %s\n",
79+
action,
80+
lesson.ChapterNumber,
81+
lesson.LessonNumber,
82+
lesson.Lesson.Title,
83+
)
8784
}
8885

8986
if lesson.Lesson.Type != "type_cli" {
@@ -133,6 +130,7 @@ func submissionHandler(cmd *cobra.Command, args []string) error {
133130
return err
134131
}
135132
}
133+
136134
return nil
137135
}
138136

0 commit comments

Comments
 (0)