From 8fccb0886f3fd46b759fef8ec3181efecc10d3d6 Mon Sep 17 00:00:00 2001 From: abs3nt Date: Sun, 18 Feb 2024 10:23:19 -0800 Subject: [PATCH] flags --- src/components/cli/cli.go | 19 +++++++++++++------ src/components/commands/downloadCover.go | 3 +++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/components/cli/cli.go b/src/components/cli/cli.go index 7fa0dd4..57ea3d6 100644 --- a/src/components/cli/cli.go +++ b/src/components/cli/cli.go @@ -96,13 +96,19 @@ 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: "download_cover ", + Name: "download_cover", + Usage: "Downloads the cover of the current song", + Aliases: []string{"dl"}, + Flags: []cli.Flag{ + &cli.PathFlag{ + Name: "path", + Aliases: []string{"p"}, + Usage: "Path to save the cover", + DefaultText: "./cover.png", + }, + }, Action: func(cCtx *cli.Context) error { - return c.DownloadCover(cCtx.Args().First()) + return c.DownloadCover(cCtx.Path("path")) }, }, { @@ -115,6 +121,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { }, }, } + app.Suggest = true if err := app.Run(os.Args); err != nil { slog.Error("COMMANDER", "run error", err) os.Exit(1) diff --git a/src/components/commands/downloadCover.go b/src/components/commands/downloadCover.go index 0c97976..b14369b 100644 --- a/src/components/commands/downloadCover.go +++ b/src/components/commands/downloadCover.go @@ -6,6 +6,9 @@ import ( ) func (c *Commander) DownloadCover(path string) error { + if path == "" { + path = "cover.png" + } destinationPath := filepath.Clean(path) state, err := c.Client.PlayerState(c.Context) if err != nil {