Skip to content

Commit

Permalink
feat(cli): Add "next" to run the next unsolved exercise. (#785)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

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

Co-authored-by: marisa <[email protected]>
  • Loading branch information
jazzplato and shadows-withal authored Jun 30, 2021
1 parent 633303d commit d20e413
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,25 @@ 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:

``` bash
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
Expand Down
25 changes: 18 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down

0 comments on commit d20e413

Please sign in to comment.