summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorKate Hart <codehearts@users.noreply.github.com>2019-12-22 12:27:38 -0800
committerKate Hart <codehearts@users.noreply.github.com>2019-12-26 20:27:49 -0800
commitd25ee55a3205882d35782e370af855051b39c58c (patch)
tree1e9570f9b5ef7f26011b55534e6d48a441fa3a17 /src/main.rs
parent426a7bb87f5ac08841bf0272887333a4a7925eae (diff)
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 #251
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index ebb61d6..dd060ac 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,6 +2,7 @@ use crate::exercise::{Exercise, ExerciseList};
use crate::run::run;
use crate::verify::verify;
use clap::{crate_version, App, Arg, SubCommand};
+use console::Emoji;
use notify::DebouncedEvent;
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
use std::ffi::OsStr;
@@ -102,7 +103,21 @@ fn main() {
}
if matches.subcommand_matches("watch").is_some() {
- watch(&exercises).unwrap();
+ if watch(&exercises).is_ok() {
+ println!(
+ "{emoji} All exercises completed! {emoji}",
+ emoji = Emoji("🎉", "★")
+ );
+ println!("");
+ println!("We hope you enjoyed learning about the various aspects of Rust!");
+ println!(
+ "If you noticed any issues, please don't hesitate to report them to our repo."
+ );
+ println!("You can also contribute your own exercises to help the greater community!");
+ println!("");
+ println!("Before reporting an issue or contributing, please read our guidelines:");
+ println!("https://github.com/rust-lang/rustlings/blob/master/CONTRIBUTING.md");
+ }
}
if matches.subcommand_name().is_none() {
@@ -144,10 +159,12 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
watcher.watch(Path::new("./exercises"), RecursiveMode::Recursive)?;
clear_screen();
- let verify_result = verify(exercises.iter());
let to_owned_hint = |t: &Exercise| t.hint.to_owned();
- let failed_exercise_hint = Arc::new(Mutex::new(verify_result.map_err(to_owned_hint).err()));
+ let failed_exercise_hint = match verify(exercises.iter()) {
+ Ok(_) => return Ok(()),
+ Err(exercise) => Arc::new(Mutex::new(Some(to_owned_hint(exercise)))),
+ };
spawn_watch_shell(&failed_exercise_hint);
loop {
match rx.recv() {
@@ -159,9 +176,13 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
.iter()
.skip_while(|e| !filepath.ends_with(&e.path));
clear_screen();
- let verify_result = verify(pending_exercises);
- let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap();
- *failed_exercise_hint = verify_result.map_err(to_owned_hint).err();
+ match verify(pending_exercises) {
+ Ok(_) => return Ok(()),
+ Err(exercise) => {
+ let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap();
+ *failed_exercise_hint = Some(to_owned_hint(exercise));
+ }
+ }
}
}
_ => {}