feat: list assets per album
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build and test / Build AMD64 (pull_request) Successful in 1m16s
				
			
		
			
				
	
				Build and test / Tests (pull_request) Successful in 1m25s
				
			
		
			
				
	
				Checking Renovate configuration / validate (pull_request) Successful in 1m55s
				
			
		
			
				
	
				Checking yaml / Run yamllint (pull_request) Successful in 36s
				
			
		
			
				
	
				Build and test / Clippy (pull_request) Successful in 31s
				
			
		
			
				
	
				Build and test / Generate Documentation (pull_request) Successful in 55s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build and test / Build AMD64 (pull_request) Successful in 1m16s
				
			Build and test / Tests (pull_request) Successful in 1m25s
				
			Checking Renovate configuration / validate (pull_request) Successful in 1m55s
				
			Checking yaml / Run yamllint (pull_request) Successful in 36s
				
			Build and test / Clippy (pull_request) Successful in 31s
				
			Build and test / Generate Documentation (pull_request) Successful in 55s
				
			This commit is contained in:
		
							parent
							
								
									07907b2ce2
								
							
						
					
					
						commit
						9ad599a2b4
					
				
					 6 changed files with 54 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -7,7 +7,6 @@ use crate::{
 | 
			
		|||
 | 
			
		||||
use super::action::Action;
 | 
			
		||||
 | 
			
		||||
#[allow(dead_code)] // Will be used soon.
 | 
			
		||||
pub struct FetchAlbumAssets {
 | 
			
		||||
    album: Album,
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -95,6 +95,13 @@ pub(crate) enum AlbumsCommands {
 | 
			
		|||
    /// List all albums
 | 
			
		||||
    #[serde(rename = "list")]
 | 
			
		||||
    List {},
 | 
			
		||||
    /// List all assets that belong to a specific album
 | 
			
		||||
    #[serde(rename = "list-assets")]
 | 
			
		||||
    ListAssets {
 | 
			
		||||
        /// Name of the album to list assets for
 | 
			
		||||
        #[arg(long)]
 | 
			
		||||
        album: String,
 | 
			
		||||
    },
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Serialize, Subcommand)]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										38
									
								
								src/commands/list_album_assets.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/commands/list_album_assets.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,38 @@
 | 
			
		|||
use crate::{
 | 
			
		||||
    actions::{
 | 
			
		||||
        action::Action, fetch_album_assets::FetchAlbumAssets, fetch_all_albums::FetchAllAlbums,
 | 
			
		||||
    },
 | 
			
		||||
    context::Context,
 | 
			
		||||
};
 | 
			
		||||
use color_eyre::eyre::{eyre, Result};
 | 
			
		||||
use tabled::{settings::Style, Table, Tabled};
 | 
			
		||||
 | 
			
		||||
#[derive(Tabled)]
 | 
			
		||||
struct AssetRow {
 | 
			
		||||
    #[tabled(rename = "Path")]
 | 
			
		||||
    original_file_path: String,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub async fn list_album_assets(ctx: Context, album_name: &str) -> Result<()> {
 | 
			
		||||
    let albums = FetchAllAlbums::new(()).execute(&ctx).await?;
 | 
			
		||||
 | 
			
		||||
    let album = albums
 | 
			
		||||
        .into_iter()
 | 
			
		||||
        .find(|a| a.name == album_name)
 | 
			
		||||
        .ok_or_else(|| eyre!("Album not found: {}", album_name))?;
 | 
			
		||||
 | 
			
		||||
    let mut assets: Vec<_> = FetchAlbumAssets::new(album)
 | 
			
		||||
        .execute(&ctx)
 | 
			
		||||
        .await?
 | 
			
		||||
        .into_iter()
 | 
			
		||||
        .map(|asset| AssetRow {
 | 
			
		||||
            original_file_path: asset.original_path.to_string_lossy().to_string(),
 | 
			
		||||
        })
 | 
			
		||||
        .collect();
 | 
			
		||||
 | 
			
		||||
    assets.sort_by_key(|row| row.original_file_path.clone());
 | 
			
		||||
 | 
			
		||||
    println!("{}", Table::new(assets).with(Style::rounded()));
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
pub mod auto_create_albums;
 | 
			
		||||
pub mod delete_albums;
 | 
			
		||||
pub mod delete_assets;
 | 
			
		||||
pub mod list_album_assets;
 | 
			
		||||
pub mod list_albums;
 | 
			
		||||
pub mod list_assets;
 | 
			
		||||
pub mod list_libraries;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@ use color_eyre::Section;
 | 
			
		|||
use commands::auto_create_albums::auto_create_albums;
 | 
			
		||||
use commands::delete_albums::delete_albums;
 | 
			
		||||
use commands::delete_assets::delete_assets;
 | 
			
		||||
use commands::list_album_assets::list_album_assets;
 | 
			
		||||
use commands::list_albums::list_albums;
 | 
			
		||||
use commands::list_assets::list_assets;
 | 
			
		||||
use commands::list_libraries::list_libraries;
 | 
			
		||||
| 
						 | 
				
			
			@ -87,6 +88,7 @@ async fn main() -> Result<()> {
 | 
			
		|||
            } => auto_create_albums(ctx, album_name_separator.to_string()).await,
 | 
			
		||||
            AlbumsCommands::Delete { empty } => delete_albums(ctx, *empty).await,
 | 
			
		||||
            AlbumsCommands::List {} => list_albums(ctx).await,
 | 
			
		||||
            AlbumsCommands::ListAssets { album } => list_album_assets(ctx, album).await,
 | 
			
		||||
        },
 | 
			
		||||
        Commands::Assets { assets_command } => match assets_command {
 | 
			
		||||
            AssetsCommands::Delete { offline } => delete_assets(ctx, *offline).await,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue