Add "run next" to run the next unsolved exercise.

This commit is contained in:
Ricthofen 2021-06-27 20:12:20 -04:00
parent a2f0401c4c
commit 7e2973b901
2 changed files with 24 additions and 7 deletions

View file

@ -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 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 In case you get stuck, you can run the following command to get a hint for your
exercise: exercise:

View file

@ -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 { fn find_exercise<'a>(name: &str, exercises: &'a [Exercise]) -> &'a Exercise {
exercises if name.eq("next") {
.iter() exercises
.find(|e| e.name == name) .iter()
.unwrap_or_else(|| { .find(|e| !e.looks_done())
println!("No exercise found for '{}'!", name); .unwrap_or_else(|| {
std::process::exit(1) 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<()> { fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> {