Skip to content

Commit

Permalink
use stderr when error
Browse files Browse the repository at this point in the history
  • Loading branch information
bestgopher committed Sep 7, 2021
1 parent 16ef36f commit f0f0624
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn write_readme(r: &mut Vec<Resp>) {

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())
}
}

Expand All @@ -41,7 +41,7 @@ pub fn get_all_bin_file() -> Vec<String> {
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;
}

Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -24,7 +26,10 @@ pub fn run() {
if let Some(matches) = matches.subcommand_matches("new") {
match matches.value_of_t::<String>("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();
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
leetcode::run()
leetcode::run();
}

0 comments on commit f0f0624

Please sign in to comment.