Skip to content

Commit e2f7380

Browse files
Merge branch 'master' of github.com:joshuathompson/baton
2 parents 8135269 + 3a6c262 commit e2f7380

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
build
2+
/baton

cmd/remove.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/joshuathompson/baton/api"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func removeTrack(cmd *cobra.Command, args []string) {
11+
ctx, err := api.GetPlayerState(nil)
12+
13+
if err != nil {
14+
fmt.Printf("Couldn't get the player state. Is Spotify active on a device? Have you authenticated with the 'auth' command?\n")
15+
return
16+
}
17+
18+
if ctx.Item == nil {
19+
fmt.Printf("Couldn't find information about the current status\n")
20+
return
21+
}
22+
23+
err = api.RemoveSavedTrack(ctx.Item.ID)
24+
if err != nil {
25+
fmt.Printf("Couldn't remove the track from saved. %s\n", err)
26+
return
27+
}
28+
}
29+
30+
func init() {
31+
rootCmd.AddCommand(removeTrackCmd)
32+
}
33+
34+
var removeTrackCmd = &cobra.Command{
35+
Use: "remove",
36+
Short: "Remove current playing track from saved",
37+
Long: `Remove current playing track from saved`,
38+
Run: removeTrack,
39+
}

cmd/save.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/joshuathompson/baton/api"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func saveTrack(cmd *cobra.Command, args []string) {
11+
ctx, err := api.GetPlayerState(nil)
12+
13+
if err != nil {
14+
fmt.Printf("Couldn't get the player state. Is Spotify active on a device? Have you authenticated with the 'auth' command?\n")
15+
return
16+
}
17+
18+
if ctx.Item == nil {
19+
fmt.Printf("Couldn't find information about the current status\n")
20+
return
21+
}
22+
23+
err = api.SaveTrack(ctx.Item.ID)
24+
if err != nil {
25+
fmt.Printf("Couldn't save the track. %s\n", err)
26+
return
27+
}
28+
}
29+
30+
func init() {
31+
rootCmd.AddCommand(saveTrackCmd)
32+
}
33+
34+
var saveTrackCmd = &cobra.Command{
35+
Use: "save",
36+
Short: "Save current playing track",
37+
Long: `Save current playing track`,
38+
Run: saveTrack,
39+
}

0 commit comments

Comments
 (0)