From d3a2695302d61575416ea9a7cd7d09c6ec3031ef Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sat, 26 Aug 2023 09:55:40 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89=20Begin=20setting=20up=20mpd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/current.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ go.mod | 6 +++++- go.sum | 2 ++ main.go | 7 +++++-- mpd/conn.go | 24 ++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 cmd/current.go create mode 100644 mpd/conn.go diff --git a/cmd/current.go b/cmd/current.go new file mode 100644 index 0000000..5af596c --- /dev/null +++ b/cmd/current.go @@ -0,0 +1,44 @@ +/* +Copyright © 2023 NAME HERE +*/ +package cmd + +import ( + "fmt" + + "codeberg.org/danjones000/mpc-plus/mpd" + "github.com/spf13/cobra" +) + +// 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: + +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) { + conn, _ := mpd.GetConn() + curr, _ := conn.CurrentSong() + for k, v := range curr { + fmt.Println(k, ":", v) + } + }, +} + +func init() { + rootCmd.AddCommand(currentCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // currentCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // currentCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/go.mod b/go.mod index 5dd9c65..18f7c1a 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,12 @@ module codeberg.org/danjones000/mpc-plus go 1.20 +require ( + github.com/fhs/gompd/v2 v2.3.0 + github.com/spf13/cobra v1.7.0 +) + require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/spf13/cobra v1.7.0 // indirect github.com/spf13/pflag v1.0.5 // indirect ) diff --git a/go.sum b/go.sum index f3366a9..b6552d2 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/fhs/gompd/v2 v2.3.0 h1:wuruUjmOODRlJhrYx73rJnzS7vTSXSU7pWmZtM3VPE0= +github.com/fhs/gompd/v2 v2.3.0/go.mod h1:nNdZtcpD5VpmzZbRl5rV6RhxeMmAWTxEsSIMBkmMIy4= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= diff --git a/main.go b/main.go index f4378c6..afc80a2 100644 --- a/main.go +++ b/main.go @@ -1,11 +1,14 @@ /* Copyright © 2023 NAME HERE - */ package main -import "codeberg.org/danjones000/mpc-plus/cmd" +import ( + "codeberg.org/danjones000/mpc-plus/cmd" + "codeberg.org/danjones000/mpc-plus/mpd" +) func main() { + defer mpd.CloseConn() cmd.Execute() } diff --git a/mpd/conn.go b/mpd/conn.go new file mode 100644 index 0000000..6b46242 --- /dev/null +++ b/mpd/conn.go @@ -0,0 +1,24 @@ +package mpd + +import ( + "github.com/fhs/gompd/v2/mpd" +) + +var conn *mpd.Client +var connerror error + +func init() { + conn, connerror = mpd.Dial("tcp", "localhost:6600") +} + +func GetConn() (*mpd.Client, error) { + return conn, connerror +} + +func CloseConn() error { + if connerror != nil { + return connerror + + } + return conn.Close() +}