1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-06-17 00:07:35 +02:00

feat(cli): Add "next" to run the next unsolved exercise. (#785)

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

* Fix a grammar error in the message.

* Update README.md with the suggested change

Co-authored-by: marisa <mokou@fastmail.com>

* Update the README.md for "rustlings hint next".

Co-authored-by: marisa <mokou@fastmail.com>
This commit is contained in:
Richthofen
2021-06-30 03:05:49 -07:00
committed by GitHub
parent 633303d4b8
commit d20e413a68
2 changed files with 30 additions and 7 deletions

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