From d7c630240c8d26df96a88ef96f381576058e52e6 Mon Sep 17 00:00:00 2001 From: w568w <1278297578@qq.com> Date: Sun, 23 Jun 2024 21:51:43 +0800 Subject: [PATCH] fix(cli): correctly print user prompt for termination --- cli/src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index a049c37..feeaa2a 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -4,8 +4,7 @@ use either::Either; use indicatif::ProgressBar; use serde::{Deserialize, Serialize}; use std::{ - fs::read_to_string, - sync::atomic::{AtomicBool, Ordering}, + fs::read_to_string, io::Write, sync::atomic::{AtomicBool, Ordering} }; /// A command line tool for importing JSON files into curriculum database. @@ -175,6 +174,7 @@ async fn main() -> Result<()> { if TERMINATE.load(Ordering::SeqCst) { let mut input = String::new(); print!("Do you want to stop the program? (y/N) "); + let _ = std::io::stdout().flush(); std::io::stdin() .read_line(&mut input) .expect("Failed to read input"); @@ -207,16 +207,17 @@ async fn main() -> Result<()> { .json(&new_course) .send() .await?; - + + pb.inc(1); + if !resq.status().is_success() { println!( "Failed to import course `{:?}`: {}", new_course, resq.text().await? ); - continue; } - pb.inc(1); + } pb.finish(); println!("Congratulations! All courses have been imported successfully!");