mpc-extra/cmd/current-rate.go
2023-08-27 20:07:00 -05:00

58 lines
1.5 KiB
Go

/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"errors"
"strconv"
"codeberg.org/danjones000/mpc-extra/mpd"
"github.com/spf13/cobra"
)
// rateCmd represents the rate command
var rateCmd = &cobra.Command{
Use: "rate [rating]",
Short: "Rates the current playing song: 0-10",
/*
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
*/
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("Missing rating")
}
num, err := strconv.Atoi(args[0])
if err != nil {
return err
}
if num < 0 || num > 10 {
return errors.New("Rating must be between zero and ten")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
curr, _ := mpd.GetCurrent()
curr.AddSticker("rating", args[0])
curr.PrintAll(true)
},
}
func init() {
currentCmd.AddCommand(rateCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// rateCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// rateCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}