From 1faea3fd7f08f01c53b86c25d51b38a01f4e00af Mon Sep 17 00:00:00 2001 From: abs3nt Date: Mon, 19 Feb 2024 10:11:47 -0800 Subject: [PATCH] v3 --- completions/_gspot | 4 +- go.mod | 5 +- go.sum | 8 +-- src/components/cli/cli.go | 109 ++++++++++++++++++-------------------- 4 files changed, 57 insertions(+), 69 deletions(-) diff --git a/completions/_gspot b/completions/_gspot index ced9c94..d18f17e 100755 --- a/completions/_gspot +++ b/completions/_gspot @@ -5,9 +5,9 @@ _cli_zsh_autocomplete() { local cur cur=${words[-1]} if [[ "$cur" == "-"* ]]; then - opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") + opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-shell-completion)}") else - opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}") + opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-shell-completion)}") fi if [[ "${opts[1]}" != "" ]]; then diff --git a/go.mod b/go.mod index 4f3ebd8..23dc64f 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/charmbracelet/bubbletea v0.25.0 github.com/charmbracelet/lipgloss v0.9.1 github.com/lmittmann/tint v1.0.4 - github.com/urfave/cli/v2 v2.27.1 + github.com/urfave/cli/v3 v3.0.0-alpha9 github.com/zmb3/spotify/v2 v2.4.1 go.uber.org/fx v1.20.1 golang.org/x/exp v0.0.0-20240213143201-ec583247a57a @@ -29,7 +29,6 @@ require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/charmbracelet/harmonica v0.2.0 // indirect github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/cristalhq/aconfig v0.18.5 // indirect github.com/cristalhq/aconfig/aconfigdotenv v0.17.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect @@ -53,9 +52,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rivo/uniseg v0.4.7-0.20240127222946-601bbb3750c2 // indirect - github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect - github.com/stretchr/testify v1.8.4 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/atomic v1.7.0 // indirect diff --git a/go.sum b/go.sum index 2823e01..08d3c02 100644 --- a/go.sum +++ b/go.sum @@ -74,8 +74,6 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= -github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cristalhq/aconfig v0.17.0/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E= github.com/cristalhq/aconfig v0.18.5 h1:QqXH/Gy2c4QUQJTV2BN8UAuL/rqZ3IwhvxeC8OgzquA= github.com/cristalhq/aconfig v0.18.5/go.mod h1:NXaRp+1e6bkO4dJn+wZ71xyaihMDYPtCSvEhMTm/H3E= @@ -217,8 +215,6 @@ github.com/rivo/uniseg v0.4.7-0.20240127222946-601bbb3750c2 h1:tcc3ZFBvjydcgrAxa github.com/rivo/uniseg v0.4.7-0.20240127222946-601bbb3750c2/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y= github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -233,8 +229,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= -github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= +github.com/urfave/cli/v3 v3.0.0-alpha9 h1:P0RMy5fQm1AslQS+XCmy9UknDXctOmG/q/FZkUFnJSo= +github.com/urfave/cli/v3 v3.0.0-alpha9/go.mod h1:0kK/RUFHyh+yIKSfWxwheGndfnrvYSmYFVeKCh03ZUc= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/src/components/cli/cli.go b/src/components/cli/cli.go index 5bc65d1..46b81a4 100644 --- a/src/components/cli/cli.go +++ b/src/components/cli/cli.go @@ -1,11 +1,12 @@ package cli import ( + "context" "fmt" "os" "strconv" - "github.com/urfave/cli/v2" + "github.com/urfave/cli/v3" "github.com/zmb3/spotify/v2" "go.uber.org/fx" @@ -16,11 +17,11 @@ import ( var Version = "dev" func Run(c *commands.Commander, s fx.Shutdowner) { - app := &cli.App{ - Name: "gspot", - EnableBashCompletion: true, - Version: Version, - Action: func(ctx *cli.Context) error { + app := &cli.Command{ + Name: "gspot", + EnableShellCompletion: true, + Version: Version, + Action: func(ctx context.Context, cmd *cli.Command) error { return tui.StartTea(c, "main") }, Commands: []*cli.Command{ @@ -28,7 +29,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "play", Aliases: []string{"pl", "start", "s"}, Usage: "Plays spotify", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.Play() }, Category: "Playback", @@ -37,10 +38,9 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "playurl", Aliases: []string{"plu"}, Usage: "Plays a spotify url", - Args: true, ArgsUsage: "url", - Action: func(ctx *cli.Context) error { - return c.PlayUrl(ctx.Args().First()) + Action: func(ctx context.Context, cmd *cli.Command) error { + return c.PlayUrl(cmd.Args().First()) }, Category: "Playback", }, @@ -48,7 +48,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "pause", Aliases: []string{"pa"}, Usage: "Pauses spotify", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.Pause() }, Category: "Playback", @@ -57,7 +57,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "toggleplay", Aliases: []string{"t"}, Usage: "Toggles play/pause", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.TogglePlay() }, Category: "Playback", @@ -66,7 +66,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "link", Aliases: []string{"yy"}, Usage: "Prints the current song's spotify link", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.PrintLink() }, Category: "Sharing", @@ -75,7 +75,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "linkcontext", Aliases: []string{"lc"}, Usage: "Prints the current album or playlist", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.PrintLinkContext() }, Category: "Sharing", @@ -84,7 +84,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "youtube-link", Aliases: []string{"yl"}, Usage: "Prints the current song's youtube link", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.PrintYoutubeLink() }, Category: "Sharing", @@ -93,11 +93,10 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "next", Aliases: []string{"n", "skip"}, Usage: "Skips to the next song", - Args: true, ArgsUsage: "amount", - Action: func(cCtx *cli.Context) error { - if cCtx.NArg() > 0 { - amt, err := strconv.Atoi(cCtx.Args().First()) + Action: func(ctx context.Context, cmd *cli.Command) error { + if cmd.NArg() > 0 { + amt, err := strconv.Atoi(cmd.Args().First()) if err != nil { return err } @@ -111,7 +110,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "previous", Aliases: []string{"b", "prev", "back"}, Usage: "Skips to the previous song", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.Previous() }, Category: "Playback", @@ -120,7 +119,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "like", Aliases: []string{"l"}, Usage: "Likes the current song", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.Like() }, Category: "Library Management", @@ -129,7 +128,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "unlike", Aliases: []string{"u"}, Usage: "Unlikes the current song", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.UnLike() }, Category: "Library Management", @@ -146,8 +145,8 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Usage: "bypass cache", }, }, - Action: func(cCtx *cli.Context) error { - return c.NowPlaying(cCtx.Bool("force")) + Action: func(ctx context.Context, cmd *cli.Command) error { + return c.NowPlaying(cmd.Bool("force")) }, Category: "Info", }, @@ -156,14 +155,13 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Aliases: []string{"v"}, Usage: "Control the volume", Category: "Playback", - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ { Name: "up", Usage: "Increase the volume", - Args: true, ArgsUsage: "percent", - Action: func(cCtx *cli.Context) error { - amt, err := strconv.Atoi(cCtx.Args().First()) + Action: func(ctx context.Context, cmd *cli.Command) error { + amt, err := strconv.Atoi(cmd.Args().First()) if err != nil { return err } @@ -174,10 +172,9 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "down", Aliases: []string{"dn"}, Usage: "Decrease the volume", - Args: true, ArgsUsage: "percent", - Action: func(cCtx *cli.Context) error { - amt, err := strconv.Atoi(cCtx.Args().First()) + Action: func(ctx context.Context, cmd *cli.Command) error { + amt, err := strconv.Atoi(cmd.Args().First()) if err != nil { return err } @@ -188,7 +185,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "mute", Aliases: []string{"m"}, Usage: "Mute", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.Mute() }, }, @@ -196,7 +193,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "unmute", Aliases: []string{"um"}, Usage: "Unmute", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.UnMute() }, }, @@ -204,7 +201,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "togglemute", Aliases: []string{"tm"}, Usage: "Toggle mute", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.ToggleMute() }, }, @@ -214,15 +211,14 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "download_cover", Usage: "Downloads the cover of the current song", Aliases: []string{"dl"}, - Args: true, ArgsUsage: "path", - BashComplete: func(cCtx *cli.Context) { - if cCtx.NArg() > 0 { + ShellComplete: func(ctx context.Context, cmd *cli.Command) { + if cmd.NArg() > 0 { return } }, - Action: func(cCtx *cli.Context) error { - return c.DownloadCover(cCtx.Args().First()) + Action: func(ctx context.Context, cmd *cli.Command) error { + return c.DownloadCover(cmd.Args().First()) }, Category: "Info", }, @@ -230,7 +226,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "radio", Usage: "Starts a radio from the current song", Aliases: []string{"r"}, - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.Radio() }, Category: "Radio", @@ -239,7 +235,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "clearradio", Usage: "Clears the radio queue", Aliases: []string{"cr"}, - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.ClearRadio() }, Category: "Radio", @@ -248,7 +244,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "refillradio", Usage: "Refills the radio queue with similar songs", Aliases: []string{"rr"}, - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.RefillRadio() }, Category: "Radio", @@ -256,7 +252,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { { Name: "status", Usage: "Prints the current status", - Action: func(ctx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.Status() }, Category: "Info", @@ -265,7 +261,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "devices", Usage: "Lists available devices", Aliases: []string{"d"}, - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.ListDevices() }, Category: "Info", @@ -273,20 +269,19 @@ func Run(c *commands.Commander, s fx.Shutdowner) { { Name: "setdevice", Usage: "Set the active device", - Args: true, ArgsUsage: "", - Action: func(cCtx *cli.Context) error { - if cCtx.NArg() == 0 { + Action: func(ctx context.Context, cmd *cli.Command) error { + if cmd.NArg() == 0 { return fmt.Errorf("no device id provided") } - return c.SetDevice(spotify.ID(cCtx.Args().First())) + return c.SetDevice(spotify.ID(cmd.Args().First())) }, Category: "Playback", }, { Name: "repeat", Usage: "Toggle repeat mode", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.Repeat() }, Category: "Playback", @@ -294,7 +289,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { { Name: "shuffle", Usage: "Toggle shuffle mode", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.Shuffle() }, Category: "Playback", @@ -302,7 +297,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { { Name: "tui", Usage: "Starts the TUI", - Action: func(ctx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return tui.StartTea(c, "main") }, }, @@ -311,19 +306,19 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Usage: "Seek to a position in the song", Aliases: []string{"sk"}, Category: "Playback", - Action: func(cCtx *cli.Context) error { - pos, err := strconv.Atoi(cCtx.Args().First()) + Action: func(ctx context.Context, cmd *cli.Command) error { + pos, err := strconv.Atoi(cmd.Args().First()) if err != nil { return err } return c.SetPosition(pos) }, - Subcommands: []*cli.Command{ + Commands: []*cli.Command{ { Name: "forward", Aliases: []string{"f"}, Usage: "Seek forward", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.Seek(true) }, }, @@ -331,7 +326,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Name: "backward", Aliases: []string{"b"}, Usage: "Seek backward", - Action: func(cCtx *cli.Context) error { + Action: func(ctx context.Context, cmd *cli.Command) error { return c.Seek(false) }, }, @@ -339,7 +334,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { }, }, } - if err := app.Run(os.Args); err != nil { + if err := app.Run(c.Context, os.Args); err != nil { c.Log.Error("COMMANDER", "run error", err) s.Shutdown(fx.ExitCode(1)) }