From a338ee6b2f292aa528d7d6ed7ce1d0873cdbb9a2 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Thu, 25 Jan 2024 10:36:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E5=8F=82=E6=95=B0=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9778ce6..34b8e87 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,36 +11,29 @@ async fn main() { let fetcher = Fetcher::new(); let args: Vec = std::env::args().collect(); - let operation = &args[1].as_str(); + let id = args[1].parse::(); - match operation { - &"get" => { - let id = args[2].parse::(); - - match id { - Ok(id) => { - if manager.problem_list.contains(&id) { - eprintln!("Problem {} exists.", id); - return; - } - - println!("Try to get problem {}...", id); - - let problem = fetcher.get_problem(id).await - .expect(&*format!("Failed to get problem {}.", id)); - - let file_name = problem.get_filename(); - println!("Get problem: {}.", file_name); - let content = problem.get_file_content().expect("Failed to format file content"); - - write_file(&file_name, &content).expect("Failed to write problem file."); - } - Err(_) => { - eprintln!("Get operation needs a usize param.") - } + match id { + Ok(id) => { + if manager.problem_list.contains(&id) { + eprintln!("Problem {} exists.", id); + return; } + + println!("Try to get problem {}...", id); + + let problem = fetcher.get_problem(id).await + .expect(&*format!("Failed to get problem {}.", id)); + + let file_name = problem.get_filename(); + println!("Get problem: {}.", file_name); + let content = problem.get_file_content().expect("Failed to format file content"); + + write_file(&file_name, &content).expect("Failed to write problem file."); + } + Err(_) => { + eprintln!("Get operation needs a usize param.") } - _ => {} } }