From 7e2973b9016a903c767388ea7b70abff5d9f3f1a Mon Sep 17 00:00:00 2001 From: Ricthofen <jazzplato@gmail.com> Date: Sun, 27 Jun 2021 20:12:20 -0400 Subject: [PATCH] Add "run next" to run the next unsolved exercise. --- README.md | 6 ++++++ src/main.rs | 25 ++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 503cf2c..4a04013 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,12 @@ In case you want to go by your own order, or want to only verify a single exerci rustlings run myExercise1 ``` +Or simply use the following command to run the very next unsolved exerice in the tutorial: + +```bash +rustlings run next +``` + In case you get stuck, you can run the following command to get a hint for your exercise: diff --git a/src/main.rs b/src/main.rs index a80ce88..f5c9eb7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -286,13 +286,24 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc<Mutex<Option<String>>>) { } fn find_exercise<'a>(name: &str, exercises: &'a [Exercise]) -> &'a Exercise { - exercises - .iter() - .find(|e| e.name == name) - .unwrap_or_else(|| { - println!("No exercise found for '{}'!", name); - std::process::exit(1) - }) + if name.eq("next") { + exercises + .iter() + .find(|e| !e.looks_done()) + .unwrap_or_else(|| { + println!("🎉 Congratulations! You have done all the exercises!"); + println!("🔚 There is no more exercises to do next!"); + std::process::exit(1) + }) + } else { + exercises + .iter() + .find(|e| e.name == name) + .unwrap_or_else(|| { + println!("No exercise found for '{}'!", name); + std::process::exit(1) + }) + } } fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> {