diff --git a/src/args.rs b/src/args.rs index 4dc08d0..13b6c3b 100644 --- a/src/args.rs +++ b/src/args.rs @@ -87,7 +87,11 @@ pub(crate) enum AlbumsCommands { }, /// Delete all albums #[serde(rename = "delete")] - Delete {}, + Delete { + /// Delete only empty albums + #[arg(short, long, action)] + empty: bool, + }, /// List all albums #[serde(rename = "list")] List {}, diff --git a/src/commands/delete_albums.rs b/src/commands/delete_albums.rs index 41a254e..9a46d6b 100644 --- a/src/commands/delete_albums.rs +++ b/src/commands/delete_albums.rs @@ -10,8 +10,10 @@ use crate::{ use color_eyre::eyre::Result; use log::info; -pub async fn delete_albums(ctx: Context) -> Result<()> { - let albums = FetchAllAlbums::new(()).execute(&ctx).await?; +pub async fn delete_albums(ctx: Context, empty: bool) -> Result<()> { + let mut albums = FetchAllAlbums::new(()).execute(&ctx).await?; + + albums.retain(|album| !empty || album.assets_count == 0); if let ConfirmResult::Positive = Confirm::new(None).execute(&ctx).await? { for album in &albums { diff --git a/src/main.rs b/src/main.rs index a1fa2f9..fd2761e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -83,7 +83,7 @@ async fn main() -> Result<()> { AlbumsCommands::AutoCreate { album_name_separator, } => auto_create_albums(ctx, album_name_separator.to_string()).await, - AlbumsCommands::Delete {} => delete_albums(ctx).await, + AlbumsCommands::Delete { empty } => delete_albums(ctx, *empty).await, AlbumsCommands::List {} => list_albums(ctx).await, }, Commands::Assets { assets_command } => match assets_command {