Skip to content

Commit

Permalink
Add logout
Browse files Browse the repository at this point in the history
  • Loading branch information
owenthereal committed Dec 26, 2017
1 parent 4e13f77 commit de6b6b1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
12 changes: 12 additions & 0 deletions cmd/spotctl/login.go → cmd/spotctl/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"net/http"
"os"

"github.com/spf13/cobra"
"github.com/zmb3/spotify"
Expand All @@ -18,6 +19,12 @@ var loginCmd = &cobra.Command{
RunE: login,
}

var logoutCmd = &cobra.Command{
Use: "logout",
Short: "Clear your local Spotify credentials",
RunE: login,
}

func login(cmd *cobra.Command, args []string) error {
state, err := generateRandomString(32)
if err != nil {
Expand All @@ -41,6 +48,11 @@ func login(cmd *cobra.Command, args []string) error {
return nil
}

func logout(cmd *cobra.Command, args []string) error {
os.Remove(tokenPath)
return nil
}

type authHandler struct {
state string
ch chan *oauth2.Token
Expand Down
13 changes: 7 additions & 6 deletions cmd/spotctl/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,39 @@ var playCmdFlagType string

var playCmd = &cobra.Command{
Use: "play [name]",
Short: "Resume playback or play a track, album, artist or playlist by name.",
Short: "Resume playback or play a track, album, artist or playlist by name",
Long: `Resume playback or find a track, album, artist or playlist by name and play it. The search type can be specified with --type.`,
RunE: play,
}

var pauseCmd = &cobra.Command{
Use: "pause",
Short: "Pause Spotify playback.",
Short: "Pause Spotify playback",
RunE: pause,
}

var nextCmd = &cobra.Command{
Use: "next",
Short: "Skip to the next song.",
Short: "Skip to the next track",
RunE: next,
}

var prevCmd = &cobra.Command{
Use: "prev",
Short: "Return to the previous song.",
Short: "Return to the previous track",
RunE: prev,
}

var volCmd = &cobra.Command{
Use: "vol [up|down|amount]",
Short: "Set the volume to an amount between 0 and 100. If up is provided, increase the volume by 10%. If Down is provided, decrease the volume by 10%.",
Short: "Set or return volume percentage",
Long: `Set volume percentage to an amount between 0 and 100. If arg is up, volume is increased by 10%. If arg is down, volume is decreased by 10%. If no arg is provided, current volume percentage is returned.`,
RunE: vol,
}

var statusCmd = &cobra.Command{
Use: "status",
Short: "Show the current player status.",
Short: "Show the current player status",
RunE: status,
}

Expand Down
9 changes: 5 additions & 4 deletions cmd/spotctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func ver(cmd *cobra.Command, args []string) {

func main() {
rootCmd.AddCommand(loginCmd)
rootCmd.AddCommand(logoutCmd)
rootCmd.AddCommand(playCmd)
rootCmd.AddCommand(pauseCmd)
rootCmd.AddCommand(nextCmd)
Expand Down Expand Up @@ -82,8 +83,8 @@ func preRootCmd(cmd *cobra.Command, args []string) {
)
auth.SetAuthInfo(spotifyClientID, spotifyClientSecret)

// skip reading token or login if this is a login command
if cmd.Use == "login" {
// skip reading token if this is a login/logout command
if cmd.Use == "login" || cmd.Use == "logout" {
return
}

Expand All @@ -108,8 +109,8 @@ func preRootCmd(cmd *cobra.Command, args []string) {
}

func postRootCmd(cmd *cobra.Command, args []string) {
// skip reading token or login if this is a login command
if cmd.Use == "login" {
// skip reading token if this is a login/logout command
if cmd.Use == "login" || cmd.Use == "logout" {
return
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/spotctl/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

var playerCmd = &cobra.Command{
Use: "player",
Short: "Show the player panel.",
Short: "Show the live player panel",
RunE: player,
}

Expand Down Expand Up @@ -69,7 +69,7 @@ func player(cmd *cobra.Command, args []string) error {
volGauge.BarColor = ui.ColorBlue
volGauge.PaddingBottom = 1

helpLabel := ui.NewPar("Press q - quit, p - play/pause, l/h - next/previous track, j/k - vol up/down, s - shuffle, r - repeat")
helpLabel := ui.NewPar("Press q - quit, p - play/pause, l/h - next/previous track, j/k - vol up/down, s - shuffle, r - repeat.")
helpLabel.X = 0
helpLabel.Y = 10
helpLabel.Width = 40
Expand Down

0 comments on commit de6b6b1

Please sign in to comment.