aboutsummaryrefslogtreecommitdiffstats
path: root/golings/cmd/run.go
diff options
context:
space:
mode:
Diffstat (limited to 'golings/cmd/run.go')
-rw-r--r--golings/cmd/run.go34
1 files changed, 20 insertions, 14 deletions
diff --git a/golings/cmd/run.go b/golings/cmd/run.go
index 552c234..7d5fef8 100644
--- a/golings/cmd/run.go
+++ b/golings/cmd/run.go
@@ -27,20 +27,7 @@ func RunCmd(infoFile string) *cobra.Command {
exercise, err = exercises.Find(args[0], infoFile)
}
- spinner := progressbar.NewOptions(
- -1, // a negative number makes turns the progress bar into a spinner
- progressbar.OptionEnableColorCodes(true),
- progressbar.OptionSetDescription(color.WhiteString("Running exercise: %s", exercise.Name)),
- progressbar.OptionOnCompletion(func() {
- color.White("\nRunning complete!\n\n")
- }),
- )
- go func() {
- for x := 0; x < 100; x++ {
- spinner.Add(1) // nolint
- time.Sleep(250 * time.Millisecond)
- }
- }()
+ spinner := RunSpinner(exercise.Name)
if errors.Is(err, exercises.ErrExerciseNotFound) {
color.White("No exercise found for '%s'", args[0])
@@ -71,3 +58,22 @@ func RunCmd(infoFile string) *cobra.Command {
},
}
}
+
+func RunSpinner(exercise string) *progressbar.ProgressBar {
+ spinner := progressbar.NewOptions(
+ -1, // a negative number makes turns the progress bar into a spinner
+ progressbar.OptionEnableColorCodes(true),
+ progressbar.OptionSetDescription(color.WhiteString("Running exercise: %s", exercise)),
+ progressbar.OptionOnCompletion(func() {
+ color.White("\nRunning complete!\n\n")
+ }),
+ )
+ go func() {
+ for x := 0; x < 100; x++ {
+ spinner.Add(1) // nolint
+ time.Sleep(250 * time.Millisecond)
+ }
+ }()
+
+ return spinner
+}