Add a command to list albums
This commit is contained in:
parent
af1af8dce1
commit
fb78298166
5 changed files with 61 additions and 1 deletions
35
src/commands/list_albums.rs
Normal file
35
src/commands/list_albums.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
use crate::{
|
||||
actions::{action::Action, fetch_all_albums::FetchAllAlbums},
|
||||
context::Context,
|
||||
};
|
||||
use chrono::{DateTime, Utc};
|
||||
use color_eyre::eyre::Result;
|
||||
use tabled::{settings::Style, Table, Tabled};
|
||||
#[derive(Tabled)]
|
||||
struct Album {
|
||||
#[tabled(rename = "Name")]
|
||||
name: String,
|
||||
#[tabled(rename = "Assets count")]
|
||||
assets_count: u32,
|
||||
#[tabled(rename = "Updated at")]
|
||||
updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
pub async fn list_albums(ctx: Context) -> Result<()> {
|
||||
let mut albums: Vec<_> = FetchAllAlbums::new(())
|
||||
.execute(&ctx)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|album| Album {
|
||||
name: album.name,
|
||||
updated_at: album.updated_at,
|
||||
assets_count: album.assets_count,
|
||||
})
|
||||
.collect();
|
||||
|
||||
albums.sort_by_key(|album| album.name.to_lowercase());
|
||||
|
||||
println!("{}", Table::new(albums).with(Style::rounded()),);
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue