Add a libraries list command #31
					 6 changed files with 66 additions and 0 deletions
				
			
		| 
						 | 
					@ -117,6 +117,9 @@ pub(crate) enum AssetsCommands {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Serialize, Subcommand)]
 | 
					#[derive(Serialize, Subcommand)]
 | 
				
			||||||
pub(crate) enum LibrariesCommands {
 | 
					pub(crate) enum LibrariesCommands {
 | 
				
			||||||
 | 
					    /// List all libraries
 | 
				
			||||||
 | 
					    #[serde(rename = "list")]
 | 
				
			||||||
 | 
					    List {},
 | 
				
			||||||
    /// Scan all libraries
 | 
					    /// Scan all libraries
 | 
				
			||||||
    #[serde(rename = "scan")]
 | 
					    #[serde(rename = "scan")]
 | 
				
			||||||
    Scan {},
 | 
					    Scan {},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@ use crate::{
 | 
				
			||||||
use chrono::{DateTime, Utc};
 | 
					use chrono::{DateTime, Utc};
 | 
				
			||||||
use color_eyre::eyre::Result;
 | 
					use color_eyre::eyre::Result;
 | 
				
			||||||
use tabled::{settings::Style, Table, Tabled};
 | 
					use tabled::{settings::Style, Table, Tabled};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Tabled)]
 | 
					#[derive(Tabled)]
 | 
				
			||||||
struct Album {
 | 
					struct Album {
 | 
				
			||||||
    #[tabled(rename = "Name")]
 | 
					    #[tabled(rename = "Name")]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,7 @@ use tabled::{
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    Table, Tabled,
 | 
					    Table, Tabled,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Tabled)]
 | 
					#[derive(Tabled)]
 | 
				
			||||||
struct Asset {
 | 
					struct Asset {
 | 
				
			||||||
    #[tabled(rename = "Path")]
 | 
					    #[tabled(rename = "Path")]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										58
									
								
								src/commands/list_libraries.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								src/commands/list_libraries.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,58 @@
 | 
				
			||||||
 | 
					use std::fmt::Display;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::{
 | 
				
			||||||
 | 
					    actions::{action::Action, fetch_all_libraries::FetchAllLibraries},
 | 
				
			||||||
 | 
					    context::Context,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					use chrono::{DateTime, Utc};
 | 
				
			||||||
 | 
					use color_eyre::eyre::Result;
 | 
				
			||||||
 | 
					use tabled::{settings::Style, Table, Tabled};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Tabled)]
 | 
				
			||||||
 | 
					struct Library {
 | 
				
			||||||
 | 
					    #[tabled(rename = "Name")]
 | 
				
			||||||
 | 
					    name: String,
 | 
				
			||||||
 | 
					    #[tabled(rename = "Assets count")]
 | 
				
			||||||
 | 
					    assets_count: u32,
 | 
				
			||||||
 | 
					    #[tabled(display_with = "display_paths", rename = "Import paths")]
 | 
				
			||||||
 | 
					    import_paths: Vec<String>,
 | 
				
			||||||
 | 
					    #[tabled(rename = "Updated at")]
 | 
				
			||||||
 | 
					    updated_at: DateTime<Utc>,
 | 
				
			||||||
 | 
					    #[tabled(display_with = "display_option", rename = "Refreshed at")]
 | 
				
			||||||
 | 
					    refreshed_at: Option<DateTime<Utc>>,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub async fn list_libraries(ctx: Context) -> Result<()> {
 | 
				
			||||||
 | 
					    let mut libraries: Vec<_> = FetchAllLibraries::new(())
 | 
				
			||||||
 | 
					        .execute(&ctx)
 | 
				
			||||||
 | 
					        .await?
 | 
				
			||||||
 | 
					        .into_iter()
 | 
				
			||||||
 | 
					        .map(|library| Library {
 | 
				
			||||||
 | 
					            name: library.name,
 | 
				
			||||||
 | 
					            assets_count: library.asset_count as u32,
 | 
				
			||||||
 | 
					            import_paths: library.import_paths,
 | 
				
			||||||
 | 
					            updated_at: library.updated_at,
 | 
				
			||||||
 | 
					            refreshed_at: library.refreshed_at,
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					        .collect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    libraries.sort_by_key(|library| library.name.to_lowercase());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    println!("{}", Table::new(libraries).with(Style::rounded()),);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Ok(())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn display_option<T>(o: &Option<T>) -> String
 | 
				
			||||||
 | 
					where
 | 
				
			||||||
 | 
					    T: Display,
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    match o {
 | 
				
			||||||
 | 
					        Some(s) => format!("{}", s),
 | 
				
			||||||
 | 
					        None => String::new(),
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fn display_paths(paths: &[String]) -> String {
 | 
				
			||||||
 | 
					    paths.join(", ")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ pub mod delete_albums;
 | 
				
			||||||
pub mod delete_assets;
 | 
					pub mod delete_assets;
 | 
				
			||||||
pub mod list_albums;
 | 
					pub mod list_albums;
 | 
				
			||||||
pub mod list_assets;
 | 
					pub mod list_assets;
 | 
				
			||||||
 | 
					pub mod list_libraries;
 | 
				
			||||||
pub mod missing_date_of_birth;
 | 
					pub mod missing_date_of_birth;
 | 
				
			||||||
pub mod scan_libraries;
 | 
					pub mod scan_libraries;
 | 
				
			||||||
pub mod server_features;
 | 
					pub mod server_features;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,6 +18,7 @@ use commands::delete_albums::delete_albums;
 | 
				
			||||||
use commands::delete_assets::delete_assets;
 | 
					use commands::delete_assets::delete_assets;
 | 
				
			||||||
use commands::list_albums::list_albums;
 | 
					use commands::list_albums::list_albums;
 | 
				
			||||||
use commands::list_assets::list_assets;
 | 
					use commands::list_assets::list_assets;
 | 
				
			||||||
 | 
					use commands::list_libraries::list_libraries;
 | 
				
			||||||
use commands::missing_date_of_birth::missing_date_of_birth;
 | 
					use commands::missing_date_of_birth::missing_date_of_birth;
 | 
				
			||||||
use commands::scan_libraries::scan_libraries;
 | 
					use commands::scan_libraries::scan_libraries;
 | 
				
			||||||
use commands::server_features::server_features;
 | 
					use commands::server_features::server_features;
 | 
				
			||||||
| 
						 | 
					@ -91,6 +92,7 @@ async fn main() -> Result<()> {
 | 
				
			||||||
            AssetsCommands::List { offline } => list_assets(ctx, *offline).await,
 | 
					            AssetsCommands::List { offline } => list_assets(ctx, *offline).await,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        Commands::Libraries { libraries_command } => match libraries_command {
 | 
					        Commands::Libraries { libraries_command } => match libraries_command {
 | 
				
			||||||
 | 
					            LibrariesCommands::List {} => list_libraries(ctx).await,
 | 
				
			||||||
            LibrariesCommands::Scan {} => scan_libraries(ctx).await,
 | 
					            LibrariesCommands::Scan {} => scan_libraries(ctx).await,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        Commands::People { people_command } => match people_command {
 | 
					        Commands::People { people_command } => match people_command {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue