| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- //! 换座位命令行入口(开发期对照用;镜像 Python CLI 参数)。
- //! 用法:
- //! cargo run -p toolbox-core --example seating_cli -- <xlsx> <班级> <样式> [策略] [--mixed] [--count N] [--seed S] [--output O]
- use std::path::PathBuf;
- use toolbox_core::seating::{run_seating, SeatingInput, Strategy};
- fn main() {
- let args: Vec<String> = std::env::args().collect();
- if args.len() < 4 {
- eprintln!("用法: seating_cli <xlsx> <班级> <样式> [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<u64> = None;
- let mut output: Option<PathBuf> = 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);
- }
- }
- }
|