gospt/runner/runner.go

39 lines
844 B
Go
Raw Normal View History

2023-01-07 07:40:39 +00:00
package runner
import (
"fmt"
2023-01-08 00:57:51 +00:00
"gospt/commands"
2023-01-08 00:03:43 +00:00
"gospt/ctx"
"gospt/tui"
2023-01-07 07:40:39 +00:00
"github.com/zmb3/spotify/v2"
)
2023-01-08 00:03:43 +00:00
func Run(ctx *ctx.Context, client *spotify.Client, args []string) error {
2023-01-07 07:40:39 +00:00
if len(args) == 0 {
2023-01-08 00:03:43 +00:00
user, err := client.CurrentUser(ctx)
2023-01-07 07:40:39 +00:00
if err != nil {
return fmt.Errorf("Failed to get current user")
}
2023-01-07 16:19:19 +00:00
fmt.Println("The following commands are currently supported:\nplay pause next shuffle\nhave fun", user.DisplayName)
2023-01-07 07:40:39 +00:00
return nil
}
switch args[0] {
case "play":
2023-01-08 00:57:51 +00:00
return commands.Play(ctx, client)
2023-01-07 07:40:39 +00:00
case "pause":
2023-01-08 00:57:51 +00:00
return commands.Pause(ctx, client)
2023-01-07 07:40:39 +00:00
case "next":
2023-01-08 00:57:51 +00:00
return commands.Skip(ctx, client)
2023-01-07 07:40:39 +00:00
case "shuffle":
2023-01-08 00:57:51 +00:00
return commands.Shuffle(ctx, client)
2023-01-08 00:03:43 +00:00
case "tracks":
2023-01-08 00:57:51 +00:00
return tui.DisplayList(ctx, client)
case "status":
return commands.Status(ctx, client)
2023-01-07 16:19:19 +00:00
default:
return fmt.Errorf("Unsupported Command")
}
}