From 367fbaef2b082d0b76cdf0a7afa015f55f5d77c5 Mon Sep 17 00:00:00 2001 From: MaurĂ­cio Antunes Date: Sat, 29 Oct 2022 23:44:11 -0300 Subject: feat: add hint command --- src/cmd/hint.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/cmd/hint.go (limited to 'src/cmd/hint.go') diff --git a/src/cmd/hint.go b/src/cmd/hint.go new file mode 100644 index 0000000..a315a91 --- /dev/null +++ b/src/cmd/hint.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "os" + + "github.com/fatih/color" + "github.com/mauricioabreu/golings/src/exercises" + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(cmdHint) +} + +var cmdHint = &cobra.Command{ + Use: "hint", + Short: "Get a hint for an exercise", + Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), + Run: func(cmd *cobra.Command, args []string) { + exercise, err := exercises.Find(args[0]) + if err != nil { + color.Red(err.Error()) + os.Exit(1) + } + color.Yellow(exercise.Hint) + }, +} -- cgit v1.2.3-70-g09d2