use anyhow::{Context, Result}; use clap::Parser; use rocie_client::{ apis::{ api_get_api::{product_by_id, products}, api_set_api::{associate_barcode, register_product}, configuration::Configuration, }, models::{Barcode, UnitAmount}, }; use crate::cli::{CliArgs, Command, ProductCommand}; mod cli; #[tokio::main] async fn main() -> Result<()> { let args = CliArgs::parse(); let mut config = Configuration::new(); "http://127.0.0.1:8080".clone_into(&mut config.base_path); match args.command { Command::Product { command } => { match command { ProductCommand::Register { name, description, parent, } => { let new_id = register_product( &config, rocie_client::models::ProductStub { description: Some(description), // TODO: Fix name, parent, }, ) .await .context("Failed to register new product")?; println!("Registered new product with id: {new_id}"); } ProductCommand::Get { id } => { let product = product_by_id(&config, id.to_string().as_str()) .await .with_context(|| format!("Failed to get product with id: {id}"))?; println!("{product:#?}"); } ProductCommand::AssociateBarcode { product_id, barcode_number, amount_value, amount_unit, } => associate_barcode( &config, product_id.to_string().as_str(), Barcode { amount: Box::new(UnitAmount { unit: amount_unit, value: amount_value as i32, }), id: barcode_number as i32, }, ) .await .context("Failed to associated barcode")?, ProductCommand::List {} => { let all = products(&config) .await .context("Failed to get all products")?; for product in all { println!("{}: {}", product.name, product.id); } } } } } Ok(()) }