🎉 Begin setting up mpd

This commit is contained in:
Dan Jones 2023-08-26 09:55:40 -05:00
commit d3a2695302
5 changed files with 80 additions and 3 deletions

44
cmd/current.go Normal file
View file

@ -0,0 +1,44 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
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")
}

6
go.mod
View file

@ -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
)

2
go.sum
View file

@ -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=

View file

@ -1,11 +1,14 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
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()
}

24
mpd/conn.go Normal file
View file

@ -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()
}