Skip to content

Commit

Permalink
Code review suggestions for list command
Browse files Browse the repository at this point in the history
  • Loading branch information
twexler committed Jul 3, 2021
1 parent 7a30163 commit 9203fd0
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions internal/playlist/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,39 @@ package playlist
import (
"fmt"
"spotify/internal"
"strings"

"github.com/brianstrauch/spotify"
"github.com/spf13/cobra"
)

func NewListCommand() *cobra.Command {
return &cobra.Command{
Use: "list",
Short: "List playlists.",
Use: "list",
Short: "List playlists.",
RunE: func(cmd *cobra.Command, args []string) error {
api, err := internal.Authenticate()
if err != nil {
return err
}
playlists, err := api.GetPlaylists()
output, err := List(api)
if err != nil {
return err
}
for _, pl := range playlists {
fmt.Println(pl.Name)
}
fmt.Print(output)
return nil
},
}
}

func List(api *spotify.API) (string, error) {
playlists, err := api.GetPlaylists()
if err != nil {
return "", err
}
var builder strings.Builder
for _, pl := range playlists {
builder.WriteString(fmt.Sprintln(pl.Name))
}
return builder.String(), nil
}

0 comments on commit 9203fd0

Please # to comment.