Skip to content

Commit d0e118d

Browse files
committed
Auto merge of rust-lang#253 - codehearts:watch-completion-message, r=fmoko
feat: Show a completion message when watching The completion message is shown only once all exercises succeed and are not annotated with "I AM NOT DONE." The watch command will also exit closes rust-lang#251 Let me know if there are any tests I could add or if the completion message should be tweaked!
2 parents 68e194f + c3faa0d commit d0e118d

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/main.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::exercise::{Exercise, ExerciseList};
22
use crate::run::run;
33
use crate::verify::verify;
44
use clap::{crate_version, App, Arg, SubCommand};
5+
use console::Emoji;
56
use notify::DebouncedEvent;
67
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
78
use std::ffi::OsStr;
@@ -102,7 +103,21 @@ fn main() {
102103
}
103104

104105
if matches.subcommand_matches("watch").is_some() {
105-
watch(&exercises).unwrap();
106+
if watch(&exercises).is_ok() {
107+
println!(
108+
"{emoji} All exercises completed! {emoji}",
109+
emoji = Emoji("🎉", "★")
110+
);
111+
println!("");
112+
println!("We hope you enjoyed learning about the various aspects of Rust!");
113+
println!(
114+
"If you noticed any issues, please don't hesitate to report them to our repo."
115+
);
116+
println!("You can also contribute your own exercises to help the greater community!");
117+
println!("");
118+
println!("Before reporting an issue or contributing, please read our guidelines:");
119+
println!("https://github.com/rust-lang/rustlings/blob/master/CONTRIBUTING.md");
120+
}
106121
}
107122

108123
if matches.subcommand_name().is_none() {
@@ -144,10 +159,12 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
144159
watcher.watch(Path::new("./exercises"), RecursiveMode::Recursive)?;
145160

146161
clear_screen();
147-
let verify_result = verify(exercises.iter());
148162

149163
let to_owned_hint = |t: &Exercise| t.hint.to_owned();
150-
let failed_exercise_hint = Arc::new(Mutex::new(verify_result.map_err(to_owned_hint).err()));
164+
let failed_exercise_hint = match verify(exercises.iter()) {
165+
Ok(_) => return Ok(()),
166+
Err(exercise) => Arc::new(Mutex::new(Some(to_owned_hint(exercise)))),
167+
};
151168
spawn_watch_shell(&failed_exercise_hint);
152169
loop {
153170
match rx.recv() {
@@ -159,9 +176,13 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
159176
.iter()
160177
.skip_while(|e| !filepath.ends_with(&e.path));
161178
clear_screen();
162-
let verify_result = verify(pending_exercises);
163-
let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap();
164-
*failed_exercise_hint = verify_result.map_err(to_owned_hint).err();
179+
match verify(pending_exercises) {
180+
Ok(_) => return Ok(()),
181+
Err(exercise) => {
182+
let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap();
183+
*failed_exercise_hint = Some(to_owned_hint(exercise));
184+
}
185+
}
165186
}
166187
}
167188
_ => {}

0 commit comments

Comments
 (0)