From d20e413a68772cd493561f2651cf244e822b7ca5 Mon Sep 17 00:00:00 2001 From: Richthofen Date: Wed, 30 Jun 2021 03:05:49 -0700 Subject: [PATCH] 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 * Update the README.md for "rustlings hint next". Co-authored-by: marisa --- README.md | 12 ++++++++++++ src/main.rs | 25 ++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ecb8bde7..bbaea0cf 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 next unsolved exercise in the course: + +```bash +rustlings run next +``` + In case you get stuck, you can run the following command to get a hint for your exercise: @@ -104,6 +110,12 @@ exercise: rustlings hint myExercise1 ``` +You can also get the hint for the next unsolved exercise with the following command: + +``` bash +rustlings hint next +``` + To check your progress, you can run the following command: ```bash rustlings list diff --git a/src/main.rs b/src/main.rs index a80ce88e..985fe34f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -286,13 +286,24 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc>>) { } 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<()> {