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
```
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:

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 {
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<()> {