diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3884b73 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +mpc-extra diff --git a/cmd/rate-skip.go b/cmd/rate-skip.go new file mode 100644 index 0000000..097d946 --- /dev/null +++ b/cmd/rate-skip.go @@ -0,0 +1,31 @@ +/* +Copyright © 2023 Dan Jones +*/ +package cmd + +import ( + "codeberg.org/danjones000/mpc-extra/mpd" + "github.com/spf13/cobra" +) + +// rateSkipCmd represents the rate-skip command +var rateSkipCmd = &cobra.Command{ + Use: "rate-skip [rating]", + Args: cobra.MinimumNArgs(1), + Short: "Rate the current song, and skip to the next", + RunE: func(cmd *cobra.Command, args []string) error { + root := cmd.Root() + root.SetArgs([]string{"current", "rate", "--", args[0]}) + root.TraverseChildren = false + err := root.Execute() + if err != nil { + return err + } + + return mpd.Next() + }, +} + +func init() { + rootCmd.AddCommand(rateSkipCmd) +} diff --git a/mpd/conn.go b/mpd/conn.go index a112656..bb60faa 100644 --- a/mpd/conn.go +++ b/mpd/conn.go @@ -20,3 +20,17 @@ func CloseConn() error { } return conn.Close() } + +func Next() error { + if connerror != nil { + return connerror + } + return conn.Next() +} + +func Previous() error { + if connerror != nil { + return connerror + } + return conn.Previous() +}