diff --git a/CHANGELOG.md b/CHANGELOG.md index 985faf7..68bfabf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# Unreleased + +## AeroCloud + +### Features + + - Add `v7 list-reusable-models` command. + # 1.1.0 - 2026-01-28 ## AeroCloud diff --git a/src/args.rs b/src/args.rs index 73e287f..919556f 100644 --- a/src/args.rs +++ b/src/args.rs @@ -272,6 +272,9 @@ pub enum AeroCloudV7Command { yaw_angle: Option, }, + #[command(about = "List reusable models")] + ListReusableModels, + #[command(about = "Create a new model")] CreateModel { #[arg( diff --git a/src/commands/aerocloud/mod.rs b/src/commands/aerocloud/mod.rs index ec27991..7a834ef 100644 --- a/src/commands/aerocloud/mod.rs +++ b/src/commands/aerocloud/mod.rs @@ -110,6 +110,9 @@ pub async fn run( ) .await } + AeroCloudV7Command::ListReusableModels => { + self::v7::list_reusable_models::run(args, &client).await + } AeroCloudV7Command::CreateModel { params } => { self::v7::create_model::run( args, diff --git a/src/commands/aerocloud/v7/list_reusable_models.rs b/src/commands/aerocloud/v7/list_reusable_models.rs new file mode 100644 index 0000000..6a4d641 --- /dev/null +++ b/src/commands/aerocloud/v7/list_reusable_models.rs @@ -0,0 +1,63 @@ +use crate::{ + aerocloud::{ + Client, + types::{ListPageModelsV7, ModelV7, PaginationOffset}, + }, + args::Args, + utils::new_dynamic_table, +}; +use chrono::Local; +use color_eyre::eyre; + +pub async fn run(args: &Args, client: &Client) -> eyre::Result<()> { + let mut all_items = vec![]; + let mut offset = PaginationOffset(0u64); + + loop { + let ListPageModelsV7 { items, nav } = client + .models_v7_list_reusable(None, Some(&offset)) + .await? + .into_inner(); + + all_items.extend(items); + + if let Some(next_offset) = nav.next_offset { + offset = PaginationOffset(next_offset); + } else { + break; + } + } + + if args.json { + println!("{}", &serde_json::to_string(&all_items)?); + } else { + print_human(&all_items); + } + + Ok(()) +} + +fn print_human(models: &[ModelV7]) { + if models.is_empty() { + println!(""); + return; + } + + let mut table = new_dynamic_table(); + table.set_header(vec!["Id", "Name", "Files", "Parts", "Created at"]); + + for model in models { + table.add_row(vec![ + format!("{}", model.id), + format!("{}", model.name), + format!("{}", model.files.len()), + format!( + "{}", + model.files.iter().map(|f| f.parts.len()).sum::() + ), + format!("{}", model.created_at.with_timezone(&Local)), + ]); + } + + println!("{table}"); +} diff --git a/src/commands/aerocloud/v7/mod.rs b/src/commands/aerocloud/v7/mod.rs index 7c718cf..99d9bef 100644 --- a/src/commands/aerocloud/v7/mod.rs +++ b/src/commands/aerocloud/v7/mod.rs @@ -5,5 +5,6 @@ pub mod create_simulation; pub mod delete_projects; pub mod delete_simulations; pub mod list_projects; +pub mod list_reusable_models; pub mod list_simulations; pub mod wait_for_simulations;