Skip to content

Commit f0f0624

Browse files
committed
use stderr when error
1 parent 16ef36f commit f0f0624

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/file.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn write_readme(r: &mut Vec<Resp>) {
2121

2222
match std::fs::write("README.md", s) {
2323
Ok(_) => (),
24-
Err(e) => println!("写入 README.md 失败,err{}", e.to_string())
24+
Err(e) => eprintln!("写入 README.md 失败,err{}", e.to_string())
2525
}
2626
}
2727

@@ -41,7 +41,7 @@ pub fn get_all_bin_file() -> Vec<String> {
4141
pub fn write_question(resp: Resp) {
4242
let file = format!("src/bin/{}.rs", resp.data.question.title_slug);
4343
if std::path::Path::new(file.as_str()).exists() {
44-
println!("{} exists", file);
44+
eprintln!("{} exists", file);
4545
return;
4646
}
4747

src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ mod all;
77

88
use clap::{App, Arg};
99

10+
use std::process;
11+
1012
pub fn run() {
1113
let matches = App::new("leetcode")
1214
.version("0.0.1")
@@ -24,7 +26,10 @@ pub fn run() {
2426
if let Some(matches) = matches.subcommand_matches("new") {
2527
match matches.value_of_t::<String>("question_name") {
2628
Ok(x) => new::new(x),
27-
Err(_) => println!("please input the name of question")
29+
Err(_) => {
30+
eprintln!("please input the name of question");
31+
process::exit(1);
32+
}
2833
}
2934
} else if matches.subcommand_matches("all").is_some() {
3035
all::all();

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
fn main() {
2-
leetcode::run()
2+
leetcode::run();
33
}

0 commit comments

Comments
 (0)