✨ Rate current track
This commit is contained in:
parent
f0b04b7c05
commit
83dc41cb8e
4 changed files with 83 additions and 9 deletions
58
cmd/current-rate.go
Normal file
58
cmd/current-rate.go
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
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")
|
||||
}
|
||||
|
|
@ -11,13 +11,15 @@ import (
|
|||
// currentCmd represents the current command
|
||||
var currentCmd = &cobra.Command{
|
||||
Use: "current",
|
||||
Short: "A brief description of your command",
|
||||
Long: `A longer description that spans multiple lines and likely contains examples
|
||||
and usage of using your command. For example:
|
||||
Short: "Shows information about the currently playing song",
|
||||
/*
|
||||
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.`,
|
||||
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.`,
|
||||
*/
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
curr, _ := mpd.GetCurrent()
|
||||
curr.PrintAll(true)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ import (
|
|||
|
||||
// stickerCmd represents the sticker command
|
||||
var stickerCmd = &cobra.Command{
|
||||
Use: "sticker",
|
||||
Use: "sticker [sticker-name]",
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Short: "A brief description of your command",
|
||||
Long: `A longer description that spans multiple lines and likely contains examples
|
||||
and usage of using your command. For example:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue