use hardware_report::{new_domain::HardwareReport, ReportConfig, ServerInfo};
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
println!("Hardware Report Library Usage Examples");
println!("======================================");
println!("\n1. Using Legacy API:");
match ServerInfo::collect() {
Ok(server_info) => {
println!(" Hostname: {}", server_info.hostname);
println!(" CPU: {}", server_info.summary.cpu_summary);
println!(" Memory: {}", server_info.summary.total_memory);
println!(" Storage: {}", server_info.summary.total_storage);
}
Err(e) => {
println!(" Error: {}", e);
}
}
println!("\n2. Type Conversion:");
match ServerInfo::collect() {
Ok(legacy_info) => {
let new_report: HardwareReport = legacy_info.into();
println!(" Converted to new format:");
println!(
" System: {} ({})",
new_report.hostname, new_report.summary.system_info.product_name
);
println!(" CPUs: {}", new_report.summary.total_gpus);
}
Err(e) => {
println!(" Error: {}", e);
}
}
println!("\n3. New Configuration API:");
let config = ReportConfig {
include_sensitive: false,
skip_sudo: true,
command_timeout: 10,
verbose: false,
};
println!(
" Created config with timeout: {} seconds",
config.command_timeout
);
println!("\n4. Pure Parsing Functions:");
use hardware_report::new_domain::parsers::cpu::parse_lscpu_output;
let sample_lscpu = r#"Model name: Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz
CPU(s): 16
Thread(s) per core: 2
Core(s) per socket: 8
Socket(s): 1
CPU MHz: 2300.000"#;
match parse_lscpu_output(sample_lscpu) {
Ok(cpu_info) => {
println!(" Parsed CPU: {}", cpu_info.model);
println!(
" Cores: {}, Threads: {}, Sockets: {}",
cpu_info.cores, cpu_info.threads, cpu_info.sockets
);
}
Err(e) => {
println!(" Parse error: {}", e);
}
}
println!("\n✅ All examples completed successfully!");
println!("\nNote: The new service factory will be available in Phase 4");
println!(" For now, use ServerInfo::collect() for actual hardware detection");
Ok(())
}