From 440b927141523c77702294844139883c0becb2c2 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 27 Aug 2023 14:48:09 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20PrintAll=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/current.go | 10 +--------- cmd/find.go | 4 +--- mpd/song.go | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/cmd/current.go b/cmd/current.go index 3b0dd2b..4a1ad07 100644 --- a/cmd/current.go +++ b/cmd/current.go @@ -4,8 +4,6 @@ Copyright © 2023 NAME HERE package cmd import ( - "fmt" - "codeberg.org/danjones000/mpc-extra/mpd" "github.com/spf13/cobra" ) @@ -22,13 +20,7 @@ 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() - for k, v := range curr.Attrs { - fmt.Println(k, ":", v) - } - sticks, _ := curr.GetStickers() - for _, v := range sticks { - fmt.Println(v.Name, "*:", v.Value) - } + curr.PrintAll(true) }, } diff --git a/cmd/find.go b/cmd/find.go index 73a53f5..98ac884 100644 --- a/cmd/find.go +++ b/cmd/find.go @@ -23,9 +23,7 @@ to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { ret, _ := mpd.Find(args...) for _, song := range ret { - for k, v := range song.Attrs { - fmt.Println(k, ":", v) - } + song.PrintAll(false) fmt.Println("-------") } }, diff --git a/mpd/song.go b/mpd/song.go index aa3c0f8..36e589c 100644 --- a/mpd/song.go +++ b/mpd/song.go @@ -1,6 +1,9 @@ package mpd -import "github.com/fhs/gompd/v2/mpd" +import ( + "fmt" + "github.com/fhs/gompd/v2/mpd" +) type Song struct { Path string @@ -29,3 +32,16 @@ func (s *Song) GetStickers() ([]mpd.Sticker, error) { return s.stickers, err } + +func (s *Song) PrintAll(withStickers bool) { + for k, v := range s.Attrs { + fmt.Println(k, ":", v) + } + if withStickers { + sticks, _ := s.GetStickers() + for _, v := range sticks { + fmt.Println(v.Name, "*:", v.Value) + } + } + +}