Add an assets list command
This commit is contained in:
parent
a8796b2728
commit
c026375ce1
5 changed files with 109 additions and 5 deletions
59
src/commands/list_assets.rs
Normal file
59
src/commands/list_assets.rs
Normal 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(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue