Add an assets list command

This commit is contained in:
Marc Plano-Lesay 2024-11-05 13:40:52 +11:00
parent a8796b2728
commit c026375ce1
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
5 changed files with 109 additions and 5 deletions

View file

@ -0,0 +1,59 @@
use crate::{
utils::assets::{fetch_all_assets, AssetQuery},
Client,
};
use color_eyre::eyre::Result;
use tabled::{
settings::{
object::{Columns, Object, Rows},
Format, Style,
},
Table, Tabled,
};
#[derive(Tabled)]
struct Asset {
#[tabled(rename = "Path")]
original_file_path: String,
#[tabled(rename = "Is offline")]
is_offline: bool,
#[tabled(rename = "Camera")]
model: String,
}
pub async fn list_assets(offline: bool, client: &Client) -> Result<()> {
let query = AssetQuery {
is_offline: if offline { Some(true) } else { None },
with_exif: true,
};
let mut assets: Vec<_> = fetch_all_assets(query, client)
.await?
.into_iter()
.map(|asset| Asset {
is_offline: asset.is_offline,
model: asset
.exif_info
.clone()
.and_then(|exif| exif.model)
.unwrap_or(String::from("(Unknown)")),
original_file_path: asset.original_path,
})
.collect();
assets.sort_by_key(|asset| asset.original_file_path.clone());
println!(
"{}",
Table::new(assets).with(Style::rounded()).modify(
Columns::single(1).not(Rows::first()),
Format::content(|s| {
match s {
"true" => "Yes".to_string(),
_ => "No".to_string(),
}
})
)
);
Ok(())
}