use iris_converter::{examples::{ image_info_roundtrip, read_iris_file_example, spectral_data_roundtrip }, explortirisdatatocsv, explortirisdatatojson}; fn main() { // println!("Running iris_rust examples..."); // println!("\nTesting spectral data..."); // spectral_data_roundtrip(); // println!("\nTesting spectral info..."); // spectral_info_roundtrip(); // println!("\nTesting other info..."); // other_info_roundtrip(); // println!("\nTesting image info..."); // image_info_roundtrip(); // println!("\nReading IRIS file..."); read_iris_file_example(); //explortirisdatatojson(&"iris_data_example.iris".to_string()); // explortirisdatatocsv( &"iris_data_example.iris".to_string()); println!("\nAll examples completed successfully!"); } use std::env; // 引入 env 模块以访问命令行参数 // fn main() { // // 收集所有命令行参数 // let args: Vec = env::args().collect(); // // 检查参数数量 // // 程序的第一个参数是它自己的名称,所以我们期望至少有两个参数 (程序名 + 文件路径) // // 最多三个参数 (程序名 + 文件路径 + 转换类型) // if args.len() < 2 || args.len() > 3 { // println!("Usage: {} [output_type (json|csv)]", args[0]); // println!(" output_type defaults to 'csv'"); // return; // 参数数量不正确,打印使用说明并退出 // } // // 获取文件路径 (第二个参数) // let file_path = &args[1]; // // 检查文件路径是否以 ".iris" 结尾 // if !file_path.ends_with(".iris") { // println!("Error: The file path must end with '.iris'."); // println!("Usage: {} [output_type (json|csv)]", args[0]); // return; // 文件路径不正确,打印错误信息并退出 // } // // 获取转换类型 (第三个参数,如果存在) // // 如果没有提供第三个参数,则 output_type_str 为 None // let output_type_str = if args.len() == 3 { // Some(args[2].as_str()) // 将 String 转换为 &str // } else { // None // 没有提供转换类型 // }; // // 根据转换类型执行相应的导出函数 // match output_type_str { // Some("json") => { // println!("Exporting '{}' to JSON...", file_path); // explortirisdatatojson(file_path); // }, // // 如果是 "csv" 或没有指定类型,则默认为 CSV // Some("csv") | None => { // println!("Exporting '{}' to CSV (default)...", file_path); // explortirisdatatocsv(file_path); // }, // _ => { // // 处理无效的转换类型 // println!("Error: Invalid output type. Please use 'json' or 'csv'."); // println!("Usage: {} [output_type (json|csv)]", args[0]); // } // } // println!("\nAll operations completed successfully!"); // }