-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathsubmit.go
57 lines (49 loc) · 1.34 KB
/
submit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package cmd
import (
"errors"
"github.com/bootdotdev/bootdev/checks"
api "github.com/bootdotdev/bootdev/client"
"github.com/bootdotdev/bootdev/render"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var forceSubmit bool
func init() {
rootCmd.AddCommand(submitCmd)
}
// submitCmd represents the submit command
var submitCmd = &cobra.Command{
Use: "submit UUID",
Args: cobra.MatchAll(cobra.RangeArgs(1, 10)),
Short: "Submit a lesson",
PreRun: compose(requireUpdated, requireAuth),
RunE: submissionHandler,
}
func submissionHandler(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
isSubmit := cmd.Name() == "submit" || forceSubmit
lessonUUID := args[0]
lesson, err := api.FetchLesson(lessonUUID)
if err != nil {
return err
}
if lesson.Lesson.Type != "type_cli" {
return errors.New("unable to run lesson: unsupported lesson type")
}
if lesson.Lesson.LessonDataCLI == nil {
return errors.New("unable to run lesson: missing lesson data")
}
data := lesson.Lesson.LessonDataCLI.CLIData
overrideBaseURL := viper.GetString("override_base_url")
results := checks.CLIChecks(data, overrideBaseURL)
if isSubmit {
failure, err := api.SubmitCLILesson(lessonUUID, results)
if err != nil {
return err
}
render.RenderSubmission(data, results, failure)
} else {
render.RenderRun(data, results)
}
return nil
}