56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
/*
|
|
Copyright © 2026 NAME HERE <EMAIL ADDRESS>
|
|
*/
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
"go_cli/internal/reindeer"
|
|
)
|
|
|
|
// danceCmd represents the dance command
|
|
var danceCmd = &cobra.Command{
|
|
Use: "dance",
|
|
Short: "Make the reindeer dance for my amusement.",
|
|
Long: `Makes many dancing reindeer.`,
|
|
PreRun: func(cmd *cobra.Command, args []string) {
|
|
fmt.Println("pre-running.")
|
|
},
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
duration := viper.GetInt("duration")
|
|
fmt.Printf("reindeer are now dancing for %d",duration)
|
|
for i:=1;i<= duration;i++ {
|
|
// prints left dancing reindeer
|
|
time.Sleep(time.Millisecond*500)
|
|
fmt.Printf("%s\r",reindeer.DanceLeft)
|
|
fmt.Print("\033[14A")
|
|
|
|
// prints right dancing reindeer
|
|
time.Sleep(time.Millisecond*500)
|
|
fmt.Printf("%s\r",reindeer.DanceRight)
|
|
fmt.Print("\033[14A")
|
|
|
|
}
|
|
fmt.Print(strings.Repeat("\n",15))
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(danceCmd)
|
|
|
|
// Here you will define your flags and configuration settings.
|
|
|
|
// Cobra supports Persistent Flags which will work for this command
|
|
// and all subcommands, e.g.:
|
|
// danceCmd.PersistentFlags().String("foo", "", "A help for foo")
|
|
|
|
// Cobra supports local flags which will only run when this command
|
|
// is called directly, e.g.:
|
|
// danceCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
|
}
|