Add an option to delete only empty albums #30
3 changed files with 10 additions and 4 deletions
|
@ -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 {},
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue