Merge branch 'delete-empty-albums' into 'main'

Add an option to delete only empty albums

See merge request kernald/immich-tools!28
This commit is contained in:
Marc Plano-Lesay 2024-12-03 08:11:03 +00:00
commit 18194dd964
3 changed files with 10 additions and 4 deletions

View file

@ -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 {},

View file

@ -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 {

View file

@ -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 {