From cb655d29f55f72d52762a3d45a0edd8f8c909771 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Tue, 17 Oct 2023 16:56:24 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20rate-skip=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + cmd/rate-skip.go | 31 +++++++++++++++++++++++++++++++ mpd/conn.go | 14 ++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 .gitignore create mode 100644 cmd/rate-skip.go 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() +}