From fb58de10372f5e6a122cd7103e38d2fd245a9865 Mon Sep 17 00:00:00 2001 From: Brian Strauch Date: Wed, 1 Dec 2021 20:44:25 -0800 Subject: [PATCH] add shell command --- go.mod | 6 ++++++ go.sum | 22 ++++++++++++++++++++++ internal/back/back.go | 2 +- internal/login/login.go | 2 +- internal/next/next.go | 2 +- internal/p/p.go | 5 ++--- internal/pause/pause.go | 2 +- internal/play/play.go | 2 +- internal/playlist/playlist.go | 2 +- internal/queue/queue.go | 2 +- internal/repeat/repeat.go | 2 +- internal/save/save.go | 2 +- internal/shuffle/shuffle.go | 2 +- internal/status/status.go | 2 +- internal/unsave/unsave.go | 2 +- internal/update/update.go | 2 +- main.go | 2 ++ 17 files changed, 45 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 1644fb5..ca70837 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.17 require ( github.com/blang/semver v3.5.1+incompatible + github.com/brianstrauch/cobra-shell v0.1.0 github.com/brianstrauch/spotify v0.7.1 github.com/olekukonko/tablewriter v0.0.5 github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 @@ -14,6 +15,7 @@ require ( ) require ( + github.com/c-bata/go-prompt v0.2.6 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.4.9 // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -23,9 +25,13 @@ require ( github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/magiconair/properties v1.8.5 // indirect + github.com/mattn/go-colorable v0.1.7 // indirect + github.com/mattn/go-isatty v0.0.12 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/mattn/go-tty v0.0.3 // indirect github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/pelletier/go-toml v1.9.3 // indirect + github.com/pkg/term v1.2.0-beta.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/afero v1.6.0 // indirect github.com/spf13/cast v1.3.1 // indirect diff --git a/go.sum b/go.sum index e89c580..ad67198 100644 --- a/go.sum +++ b/go.sum @@ -47,8 +47,12 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= +github.com/brianstrauch/cobra-shell v0.1.0 h1:eT+Km73w6443XjXyKRdb6ruMNnmllgHt2Vh1Uxyvhuw= +github.com/brianstrauch/cobra-shell v0.1.0/go.mod h1:LN1dyeUALI56MuTodOvqV8EA0fwy7eRnrvBir6fw1Mo= github.com/brianstrauch/spotify v0.7.1 h1:tkRH07ctLTJ8zr+0HQQYVyVxbGV/FP9xgzy8Ef/Sbew= github.com/brianstrauch/spotify v0.7.1/go.mod h1:KGmim5eCKSgu5y+jOrJPa8fxTFfy0GzeidodVnjGnUM= +github.com/c-bata/go-prompt v0.2.6 h1:POP+nrHE+DfLYx370bedwNhsqmpCUynWPxuHi0C5vZI= +github.com/c-bata/go-prompt v0.2.6/go.mod h1:/LMAke8wD2FsNu9EXNdHxNLbd9MedkPnCdfpU9wwHfY= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= @@ -194,9 +198,19 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw= +github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI= +github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -222,6 +236,8 @@ github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 h1:acNfDZXmm28D2Yg/c3A github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= +github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw= +github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= @@ -395,6 +411,7 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -404,10 +421,13 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -421,6 +441,8 @@ golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/internal/back/back.go b/internal/back/back.go index 79043fc..104d10c 100644 --- a/internal/back/back.go +++ b/internal/back/back.go @@ -13,7 +13,7 @@ func NewCommand() *cobra.Command { return &cobra.Command{ Use: "back", Aliases: []string{"b"}, - Short: "skip to previous song", + Short: "Skip to previous song.", RunE: func(cmd *cobra.Command, _ []string) error { api, err := internal.Authenticate() if err != nil { diff --git a/internal/login/login.go b/internal/login/login.go index daf2023..7af3ab8 100644 --- a/internal/login/login.go +++ b/internal/login/login.go @@ -27,7 +27,7 @@ const RedirectURI = "http://localhost:1024/callback" func NewCommand() *cobra.Command { return &cobra.Command{ Use: "login", - Short: "log in to spotify", + Short: "Log in to Spotify.", RunE: func(cmd *cobra.Command, _ []string) error { token, err := login() if err != nil { diff --git a/internal/next/next.go b/internal/next/next.go index f348564..b994278 100644 --- a/internal/next/next.go +++ b/internal/next/next.go @@ -13,7 +13,7 @@ func NewCommand() *cobra.Command { return &cobra.Command{ Use: "next", Aliases: []string{"n"}, - Short: "skip to next song", + Short: "Skip to next song.", RunE: func(cmd *cobra.Command, _ []string) error { api, err := internal.Authenticate() if err != nil { diff --git a/internal/p/p.go b/internal/p/p.go index e0db637..4541baa 100644 --- a/internal/p/p.go +++ b/internal/p/p.go @@ -12,9 +12,8 @@ import ( func NewCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "p [song]", - // Keep hidden, since this command is an alias. - Hidden: true, + Use: "p [song]", + Hidden: true, // Keep hidden, since this command is an alias. RunE: func(cmd *cobra.Command, args []string) error { api, err := internal.Authenticate() if err != nil { diff --git a/internal/pause/pause.go b/internal/pause/pause.go index bbd4a80..0792aba 100644 --- a/internal/pause/pause.go +++ b/internal/pause/pause.go @@ -12,7 +12,7 @@ import ( func NewCommand() *cobra.Command { return &cobra.Command{ Use: "pause", - Short: "pause music", + Short: "Pause music.", RunE: func(cmd *cobra.Command, _ []string) error { api, err := internal.Authenticate() if err != nil { diff --git a/internal/play/play.go b/internal/play/play.go index 1a54994..98ffab4 100644 --- a/internal/play/play.go +++ b/internal/play/play.go @@ -14,7 +14,7 @@ import ( func NewCommand() *cobra.Command { cmd := &cobra.Command{ Use: "play [song]", - Short: "play current song, or a specific song", + Short: "Play current song, or a specific song.", RunE: func(cmd *cobra.Command, args []string) error { api, err := internal.Authenticate() if err != nil { diff --git a/internal/playlist/playlist.go b/internal/playlist/playlist.go index 0c5ce1b..95ff1b0 100644 --- a/internal/playlist/playlist.go +++ b/internal/playlist/playlist.go @@ -7,7 +7,7 @@ import ( func NewCommand() *cobra.Command { cmd := &cobra.Command{ Use: "playlist", - Short: "manage playlists", + Short: "Manage playlists.", } cmd.AddCommand(NewListCommand()) diff --git a/internal/queue/queue.go b/internal/queue/queue.go index bfedd68..fe512aa 100644 --- a/internal/queue/queue.go +++ b/internal/queue/queue.go @@ -13,7 +13,7 @@ func NewCommand() *cobra.Command { return &cobra.Command{ Use: "queue song", Aliases: []string{"q"}, - Short: "queue a specific song", + Short: "Queue a specific song.", Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { api, err := internal.Authenticate() diff --git a/internal/repeat/repeat.go b/internal/repeat/repeat.go index dda1ed1..5372a93 100644 --- a/internal/repeat/repeat.go +++ b/internal/repeat/repeat.go @@ -16,7 +16,7 @@ const ( func NewCommand() *cobra.Command { return &cobra.Command{ Use: "repeat [on|off|track]", - Short: "set repeat to on, off, or track", + Short: "Set repeat to on, off, or track.", Args: cobra.ExactValidArgs(1), ValidArgs: []string{"on", "off", "track"}, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/internal/save/save.go b/internal/save/save.go index 2aed2b1..7d19031 100644 --- a/internal/save/save.go +++ b/internal/save/save.go @@ -10,7 +10,7 @@ import ( func NewCommand() *cobra.Command { return &cobra.Command{ Use: "save", - Short: "save the current song", + Short: "Save the current song.", RunE: func(cmd *cobra.Command, _ []string) error { api, err := internal.Authenticate() if err != nil { diff --git a/internal/shuffle/shuffle.go b/internal/shuffle/shuffle.go index 7f29cad..e2ef101 100644 --- a/internal/shuffle/shuffle.go +++ b/internal/shuffle/shuffle.go @@ -10,7 +10,7 @@ import ( func NewCommand() *cobra.Command { return &cobra.Command{ Use: "shuffle [on|off]", - Short: "turn shuffle on or off", + Short: "Turn shuffle on or off.", Args: cobra.ExactValidArgs(1), ValidArgs: []string{"on", "off"}, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/internal/status/status.go b/internal/status/status.go index 27789d2..1c4629b 100644 --- a/internal/status/status.go +++ b/internal/status/status.go @@ -21,7 +21,7 @@ func NewCommand() *cobra.Command { return &cobra.Command{ Use: "status", Aliases: []string{"s"}, - Short: "show the current song or episode", + Short: "Show the current song or episode.", RunE: func(cmd *cobra.Command, _ []string) error { api, err := internal.Authenticate() if err != nil { diff --git a/internal/unsave/unsave.go b/internal/unsave/unsave.go index 5acc80b..06f3ce6 100644 --- a/internal/unsave/unsave.go +++ b/internal/unsave/unsave.go @@ -10,7 +10,7 @@ import ( func NewCommand() *cobra.Command { return &cobra.Command{ Use: "unsave", - Short: "unsave the current song", + Short: "Unsave the current song.", RunE: func(cmd *cobra.Command, _ []string) error { api, err := internal.Authenticate() if err != nil { diff --git a/internal/update/update.go b/internal/update/update.go index d08400c..26df5a5 100644 --- a/internal/update/update.go +++ b/internal/update/update.go @@ -15,7 +15,7 @@ const repo = "brianstrauch/spotify-cli" func NewCommand() *cobra.Command { return &cobra.Command{ Use: "update", - Short: "update CLI to the latest version", + Short: "Update CLI to the latest version.", RunE: func(cmd *cobra.Command, _ []string) error { isUpdated, err := IsUpdated(cmd) if err != nil { diff --git a/main.go b/main.go index 343a990..aaf0e19 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "time" + shell "github.com/brianstrauch/cobra-shell" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -50,6 +51,7 @@ func main() { root.AddCommand(queue.NewCommand()) root.AddCommand(repeat.NewCommand()) root.AddCommand(save.NewCommand()) + root.AddCommand(shell.New(root)) root.AddCommand(shuffle.NewCommand()) root.AddCommand(status.NewCommand()) root.AddCommand(unsave.NewCommand())