diff options
| author | Richthofen <jazzplato@gmail.com> | 2021-06-30 03:05:49 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-30 12:05:49 +0200 |
| commit | d20e413a68772cd493561f2651cf244e822b7ca5 (patch) | |
| tree | ac39e274c8d165fd4f8854910ddbb438a371343f /src | |
| parent | 633303d4b8163e349c118c6cbd216185efe2ba24 (diff) | |
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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index a80ce88..985fe34 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 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<()> { |
