From 95c64ebd707b457b918341c1f7c0dc456b63559d Mon Sep 17 00:00:00 2001 From: abs3nt Date: Sat, 14 Oct 2023 09:47:03 -0700 Subject: [PATCH] add force argument to now playing --- cmd/nowplaying.go | 3 ++- src/commands/commands.go | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/nowplaying.go b/cmd/nowplaying.go index 4974a39..69f64f0 100644 --- a/cmd/nowplaying.go +++ b/cmd/nowplaying.go @@ -13,7 +13,8 @@ var nowPlayingCmd = &cobra.Command{ Aliases: []string{"now"}, Short: "Shows song and artist of currently playing song", Long: `Shows song and artist of currently playing song, useful for scripting`, + Args: cobra.MatchAll(cobra.RangeArgs(0, 1)), Run: func(cmd *cobra.Command, args []string) { - commands.NowPlaying(ctx) + commands.NowPlaying(ctx, args) }, } diff --git a/src/commands/commands.go b/src/commands/commands.go index 0e3dc3d..479c46e 100644 --- a/src/commands/commands.go +++ b/src/commands/commands.go @@ -962,7 +962,18 @@ func (c *Commands) LinkContext(ctx *gctx.Context) (string, error) { return state.PlaybackContext.ExternalURLs["spotify"], nil } -func (c *Commands) NowPlaying(ctx *gctx.Context) error { +func (c *Commands) NowPlaying(ctx *gctx.Context, args []string) error { + if len(args) > 0 { + if args[0] == "force" { + current, err := c.Client().PlayerCurrentlyPlaying(ctx) + if err != nil { + return err + } + str := FormatSong(current) + fmt.Println(str) + return nil + } + } song, err := cache.DefaultCache().GetOrDo("now_playing", func() (string, error) { current, err := c.Client().PlayerCurrentlyPlaying(ctx) if err != nil {