blob: 300478f272d43c5e6ddbc4781f6566bd417f45fc (
plain)
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
|
package cmd
import (
"os"
"github.com/fatih/color"
"github.com/mauricioabreu/golings/src/exercises"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(cmdRun)
}
var cmdRun = &cobra.Command{
Use: "run [exercise]",
Short: "Run a single exercise",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
result, err := exercises.Run(args[0])
if err != nil {
color.Red("Compilation of %s failed! Compiler error message:\n\n%s", result.Exercise.Path, result.Err)
color.Yellow("If you feel stuck, ask a hint by executing `golings hint %s`", result.Exercise.Name)
os.Exit(1)
} else {
color.Green("Congratulations!\n\n")
color.Green("Remove the 'I AM NOT DONE' from the file to keep going\n")
color.Green("Here is the output of your program:\n\n")
color.Cyan(result.Out)
os.Exit(0)
}
},
}
|