aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd/hint.go
blob: a315a911d4e51c593cd0a9c3336f4767c030442d (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
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)
	},
}