From 8e5b932bcf6f7aeda66f781435df163d1c83fc80 Mon Sep 17 00:00:00 2001 From: Meredith Doan Date: Fri, 6 Feb 2026 14:00:02 -0700 Subject: [PATCH] added reset all feature --- src/main.rs | 14 +++++++++++--- tests/integration_tests.rs | 9 +++++++++ website/content/usage/index.md | 7 +++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index ffd2dfa75b..2e46513828 100644 --- a/src/main.rs +++ b/src/main.rs @@ -176,9 +176,17 @@ fn main() -> Result { } } 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 { diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index bb3a084b22..6667b5057b 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -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() diff --git a/website/content/usage/index.md b/website/content/usage/index.md index 88dabf4ae4..3288c1fca3 100644 --- a/website/content/usage/index.md +++ b/website/content/usage/index.md @@ -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 `: 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 💡