Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,17 @@ fn main() -> Result<ExitCode> {
}
}
Some(Subcommands::Reset { name }) => {
app_state.set_current_exercise_by_name(&name)?;
let exercise_path = app_state.reset_current_exercise()?;
println!("The exercise {exercise_path} has been reset");
if name == "all" {
let n_exercises = app_state.exercises().len();
for ind in 0..n_exercises {
app_state.reset_exercise_by_ind(ind)?;
}
println!("All exercises have been reset");
} else {
app_state.set_current_exercise_by_name(&name)?;
let exercise_path = app_state.reset_current_exercise()?;
println!("The exercise {exercise_path} has been reset");
}
}
Some(Subcommands::Hint { name }) => {
if let Some(name) = name {
Expand Down
9 changes: 9 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ fn reset_without_exercise_name() {
Cmd::default().args(&["reset"]).fail();
}

#[test]
fn reset_all() {
Cmd::default()
.current_dir("tests/test_exercises")
.args(&["reset", "all"])
.output(PartialStdout("All exercises have been reset"))
.success();
}

#[test]
fn hint() {
Cmd::default()
Expand Down
7 changes: 7 additions & 0 deletions website/content/usage/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ The list allows you to…

See the footer of the list for all possible keys.

## Resetting Exercises

You can reset an exercise to its original state using the `reset` command:

- `rustlings reset <exercise_name>`: Reset a single exercise
- `rustlings reset all`: Reset all exercises

## Questions?

If you need any help while doing the exercises and the builtin hints aren't helpful, feel free to ask in the [_Q&A_ discussions](https://github.com/rust-lang/rustlings/discussions/categories/q-a?discussions_q=) if your question isn't answered there 💡
Expand Down