Add an option to delete only empty albums

This commit is contained in:
Marc Plano-Lesay 2024-12-03 19:09:07 +11:00
parent 0ac02c34c6
commit 776c9b005f
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
3 changed files with 10 additions and 4 deletions

View file

@ -87,7 +87,11 @@ pub(crate) enum AlbumsCommands {
}, },
/// Delete all albums /// Delete all albums
#[serde(rename = "delete")] #[serde(rename = "delete")]
Delete {}, Delete {
/// Delete only empty albums
#[arg(short, long, action)]
empty: bool,
},
/// List all albums /// List all albums
#[serde(rename = "list")] #[serde(rename = "list")]
List {}, List {},

View file

@ -10,8 +10,10 @@ use crate::{
use color_eyre::eyre::Result; use color_eyre::eyre::Result;
use log::info; use log::info;
pub async fn delete_albums(ctx: Context) -> Result<()> { pub async fn delete_albums(ctx: Context, empty: bool) -> Result<()> {
let albums = FetchAllAlbums::new(()).execute(&ctx).await?; 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? { if let ConfirmResult::Positive = Confirm::new(None).execute(&ctx).await? {
for album in &albums { for album in &albums {

View file

@ -83,7 +83,7 @@ async fn main() -> Result<()> {
AlbumsCommands::AutoCreate { AlbumsCommands::AutoCreate {
album_name_separator, album_name_separator,
} => auto_create_albums(ctx, album_name_separator.to_string()).await, } => 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, AlbumsCommands::List {} => list_albums(ctx).await,
}, },
Commands::Assets { assets_command } => match assets_command { Commands::Assets { assets_command } => match assets_command {