From f0f0624ac10713a8b831d1c1ac6caf2bb5aec9b9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 7 Sep 2021 10:13:31 +0800 Subject: [PATCH] use stderr when error --- src/file.rs | 4 ++-- src/lib.rs | 7 ++++++- src/main.rs | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/file.rs b/src/file.rs index 25ba4f31..6591e983 100644 --- a/src/file.rs +++ b/src/file.rs @@ -21,7 +21,7 @@ pub fn write_readme(r: &mut Vec) { match std::fs::write("README.md", s) { Ok(_) => (), - Err(e) => println!("写入 README.md 失败,err{}", e.to_string()) + Err(e) => eprintln!("写入 README.md 失败,err{}", e.to_string()) } } @@ -41,7 +41,7 @@ pub fn get_all_bin_file() -> Vec { pub fn write_question(resp: Resp) { let file = format!("src/bin/{}.rs", resp.data.question.title_slug); if std::path::Path::new(file.as_str()).exists() { - println!("{} exists", file); + eprintln!("{} exists", file); return; } diff --git a/src/lib.rs b/src/lib.rs index 993a91c2..d4ee68e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,8 @@ mod all; use clap::{App, Arg}; +use std::process; + pub fn run() { let matches = App::new("leetcode") .version("0.0.1") @@ -24,7 +26,10 @@ pub fn run() { if let Some(matches) = matches.subcommand_matches("new") { match matches.value_of_t::("question_name") { Ok(x) => new::new(x), - Err(_) => println!("please input the name of question") + Err(_) => { + eprintln!("please input the name of question"); + process::exit(1); + } } } else if matches.subcommand_matches("all").is_some() { all::all(); diff --git a/src/main.rs b/src/main.rs index 449447a2..68ec8695 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,3 @@ fn main() { - leetcode::run() + leetcode::run(); }