Skip to content

Commit d20e413

Browse files
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>
1 parent 633303d commit d20e413

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,25 @@ In case you want to go by your own order, or want to only verify a single exerci
9797
rustlings run myExercise1
9898
```
9999

100+
Or simply use the following command to run the next unsolved exercise in the course:
101+
102+
```bash
103+
rustlings run next
104+
```
105+
100106
In case you get stuck, you can run the following command to get a hint for your
101107
exercise:
102108

103109
``` bash
104110
rustlings hint myExercise1
105111
```
106112

113+
You can also get the hint for the next unsolved exercise with the following command:
114+
115+
``` bash
116+
rustlings hint next
117+
```
118+
107119
To check your progress, you can run the following command:
108120
```bash
109121
rustlings list

src/main.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,24 @@ fn spawn_watch_shell(failed_exercise_hint: &Arc<Mutex<Option<String>>>) {
286286
}
287287

288288
fn find_exercise<'a>(name: &str, exercises: &'a [Exercise]) -> &'a Exercise {
289-
exercises
290-
.iter()
291-
.find(|e| e.name == name)
292-
.unwrap_or_else(|| {
293-
println!("No exercise found for '{}'!", name);
294-
std::process::exit(1)
295-
})
289+
if name.eq("next") {
290+
exercises
291+
.iter()
292+
.find(|e| !e.looks_done())
293+
.unwrap_or_else(|| {
294+
println!("🎉 Congratulations! You have done all the exercises!");
295+
println!("🔚 There are no more exercises to do next!");
296+
std::process::exit(1)
297+
})
298+
} else {
299+
exercises
300+
.iter()
301+
.find(|e| e.name == name)
302+
.unwrap_or_else(|| {
303+
println!("No exercise found for '{}'!", name);
304+
std::process::exit(1)
305+
})
306+
}
296307
}
297308

298309
fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> {

0 commit comments

Comments
 (0)