(cmd *cobra.Command, args []string)
| 37 | } |
| 38 | |
| 39 | func submissionHandler(cmd *cobra.Command, args []string) error { |
| 40 | cmd.SilenceUsage = true |
| 41 | isSubmit := cmd.Name() == "submit" || forceSubmit |
| 42 | lessonUUID := args[0] |
| 43 | |
| 44 | lesson, err := api.FetchLesson(lessonUUID) |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | if lesson.Lesson.Type != "type_cli" { |
| 49 | return errors.New("unable to run lesson: unsupported lesson type") |
| 50 | } |
| 51 | if lesson.Lesson.LessonDataCLI == nil { |
| 52 | return errors.New("unable to run lesson: missing lesson data") |
| 53 | } |
| 54 | |
| 55 | data := lesson.Lesson.LessonDataCLI.CLIData |
| 56 | |
| 57 | isAllowedOS := false |
| 58 | for _, system := range data.AllowedOperatingSystems { |
| 59 | if system == runtime.GOOS { |
| 60 | isAllowedOS = true |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if !isAllowedOS { |
| 65 | return fmt.Errorf("lesson is not supported for your operating system (%s); try again with one of the following: %v", runtime.GOOS, data.AllowedOperatingSystems) |
| 66 | } |
| 67 | |
| 68 | overrideBaseURL := viper.GetString("override_base_url") |
| 69 | if overrideBaseURL != "" { |
| 70 | fmt.Printf("Using overridden base_url: %v\n", overrideBaseURL) |
| 71 | fmt.Printf("You can reset to the default with `bootdev config base_url --reset`\n\n") |
| 72 | } |
| 73 | |
| 74 | ch := make(chan tea.Msg, 1) |
| 75 | // StartRenderer and returns immediately, finalise function blocks the execution until the renderer is closed. |
| 76 | finalise := render.StartRenderer(data, isSubmit, ch) |
| 77 | |
| 78 | cliResults := checks.CLIChecks(data, overrideBaseURL, ch) |
| 79 | |
| 80 | if isSubmit { |
| 81 | submissionEvent, debugData, err := api.SubmitCLILesson(lessonUUID, cliResults, debugSubmission) |
| 82 | if debugSubmission { |
| 83 | var debugPath string |
| 84 | var debugWriteErr error |
| 85 | defer func() { |
| 86 | reportDebugFileWrite(debugPath, debugWriteErr) |
| 87 | }() |
| 88 | debugPath, debugWriteErr = writeSubmissionDebugFile(lessonUUID, debugData) |
| 89 | } |
| 90 | if err != nil { |
| 91 | return err |
| 92 | } |
| 93 | checks.ApplySubmissionResults(data, submissionEvent.StructuredErrCLI, ch) |
| 94 | finalise(submissionEvent) |
| 95 | } else { |
| 96 | finalise(api.LessonSubmissionEvent{}) |
nothing calls this directly
no test coverage detected