diff --git a/internal/api/api.go b/internal/api/api.go index e654025..8091a2a 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -2,6 +2,8 @@ package api import ( "fmt" + "os" + "path/filepath" "gospt/internal/commands" "gospt/internal/gctx" @@ -12,9 +14,15 @@ import ( func Run(ctx *gctx.Context, client *spotify.Client, args []string) error { if len(args) == 0 { + configDir, _ := os.UserConfigDir() + if _, err := os.Stat(filepath.Join(configDir, "gospt/device.json")); err != nil { + return tui.DisplayDevices(ctx, client) + } return tui.DisplayMain(ctx, client) } switch args[0] { + case "help", "--help": + return commands.PrintHelp(ctx) case "play": return commands.Play(ctx, client) case "pause": diff --git a/internal/commands/commands.go b/internal/commands/commands.go index ddfac7d..5f05abd 100644 --- a/internal/commands/commands.go +++ b/internal/commands/commands.go @@ -16,6 +16,14 @@ import ( "github.com/zmb3/spotify/v2" ) +func PrintHelp(ctx *gctx.Context) error { + fmt.Println("Usage: gospt [command]") + fmt.Println("if no command is provided then TUI will open") + fmt.Println("\ncurrently available commands:") + fmt.Println("help, play, pause, toggleplay, \nnext, previous, playurl, like, unlike, shuffle, \nrepeat, radio, clearradio, refillradio, tracks, \nclearradio, playlists, status, devices, nowplaying, setdevice") + return nil +} + func Play(ctx *gctx.Context, client *spotify.Client) error { err := client.Play(ctx) if err != nil { diff --git a/internal/tui/device.go b/internal/tui/device.go index b883890..9414e58 100644 --- a/internal/tui/device.go +++ b/internal/tui/device.go @@ -43,14 +43,16 @@ func (m deviceModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Quit } if msg.String() == "enter" { - fmt.Println("SELECTING") device := m.list.SelectedItem() var err error err = commands.SetDevice(m.ctx, m.client, device.(deviceItem).PlayerDevice) if err != nil { m.ctx.Printf(err.Error()) } - fmt.Println("DEVICE SET") + err = DisplayMain(m.ctx, m.client) + if err != nil { + return m, tea.Quit + } return m, tea.Quit } case tea.MouseMsg: diff --git a/internal/tui/main.go b/internal/tui/main.go index ed3c04c..ab196e7 100644 --- a/internal/tui/main.go +++ b/internal/tui/main.go @@ -118,7 +118,7 @@ func DisplayMain(ctx *gctx.Context, client *spotify.Client) error { ctx: ctx, client: client, } - m.list.Title = "Saved Tracks" + m.list.Title = "GOSPT" p := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion()) diff --git a/internal/tui/playlisttracks.go b/internal/tui/playlisttracks.go index 328d4e5..c32c23a 100644 --- a/internal/tui/playlisttracks.go +++ b/internal/tui/playlisttracks.go @@ -134,7 +134,7 @@ func PlaylistTracks(ctx *gctx.Context, client *spotify.Client, playlist spotify. client: client, playlist: playlist, } - m.list.Title = "Saved Tracks" + m.list.Title = playlist.Name p := tea.NewProgram(m, tea.WithAltScreen(), tea.WithMouseCellMotion())