refactor: rework output directory handling

This commit is contained in:
Mathis Maquenne
2025-05-19 15:38:18 +02:00
parent 674eb99ffd
commit 68f22ce571
8 changed files with 76 additions and 111 deletions
+2 -3
View File
@@ -20,7 +20,6 @@ var downloadCmd = &cobra.Command{
func init() {
RootCmd.AddCommand(downloadCmd)
downloadCmd.PersistentFlags().StringVarP(&opts.OutputDir, "output", "o", "", "output directory (default $HOME/Music/GoDeez)")
downloadCmd.PersistentFlags().StringVarP(&opts.Quality, "quality", "q", "best", "download quality [mp3_128, mp3_320, flac, best]")
downloadCmd.PersistentFlags().DurationVarP(&opts.Timeout, "timeout", "t", 2*time.Minute, "timeout for each download (e.g. 10s, 1m, 2m30s)")
downloadCmd.PersistentFlags().BoolVar(&opts.BPM, "bpm", false, "fetch BPM/key and add to file tags")
@@ -37,11 +36,11 @@ func newDownloadCmd(resourceType string) *cobra.Command {
Short: fmt.Sprintf("Download songs from %s", resourceType),
Args: cobra.ExactArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(appCtx.AppDir)
return opts.Validate()
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
dl := downloader.New(appCtx, resourceType)
dl := downloader.New(appConfig, resourceType)
if err := dl.Run(ctx, opts, args[0]); err != nil {
if errors.Is(err, context.Canceled) {