//! 换座位命令行入口(开发期对照用;镜像 Python CLI 参数)。 //! 用法: //! cargo run -p toolbox-core --example seating_cli -- <班级> <样式> [策略] [--mixed] [--count N] [--seed S] [--output O] use std::path::PathBuf; use toolbox_core::seating::{run_seating, SeatingInput, Strategy}; fn main() { let args: Vec = std::env::args().collect(); if args.len() < 4 { eprintln!("用法: seating_cli <班级> <样式> [good-with-good|good-with-bad|random] [--mixed] [--count N] [--seed S] [--output O]"); std::process::exit(2); } let excel = PathBuf::from(&args[1]); let class = args[2].clone(); let style = args[3].clone(); let mut strategy = Strategy::GoodWithGood; let mut allow_mixed = false; let mut count = 1usize; let mut seed: Option = None; let mut output: Option = None; let mut i = 4; while i < args.len() { match args[i].as_str() { "--mixed" => allow_mixed = true, "--count" => { i += 1; count = args[i].parse().unwrap_or(1); } "--seed" => { i += 1; seed = Some(args[i].parse().expect("seed 必须为数字")); } "--output" => { i += 1; output = Some(PathBuf::from(&args[i])); } "good-with-good" => strategy = Strategy::GoodWithGood, "good-with-bad" => strategy = Strategy::GoodWithBad, "random" => strategy = Strategy::Random, _ => { eprintln!("未知参数: {}", args[i]); std::process::exit(2); } } i += 1; } let inp = SeatingInput { excel_path: excel, sheet: None, class_name: class, style, strategy, allow_mixed, count, seed, output, }; match run_seating(&inp) { Ok(res) => { for l in &res.log { println!("{}", l); } } Err(e) => { eprintln!("{}", e); std::process::exit(1); } } }