diff --git a/src/main.rs b/src/main.rs index a06f0c56..bc4ffa5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use crate::exercise::{Exercise, ExerciseList}; use crate::project::RustAnalyzerProject; -use crate::run::{reset, run}; +use crate::run::{reset, run, reset_all}; use crate::verify::verify; use clap::{Parser, Subcommand}; use console::Emoji; @@ -55,6 +55,9 @@ enum Subcommands { Reset { /// The name of the exercise name: String, + }, + ResetAll { + }, /// Return a hint for the given exercise Hint { @@ -184,6 +187,9 @@ fn main() { run(exercise, verbose).unwrap_or_else(|_| std::process::exit(1)); } + Subcommands::ResetAll {} => { + reset_all(&exercises).unwrap_or_else(|_| std::process::exit(1)); + } Subcommands::Reset { name } => { let exercise = find_exercise(&name, &exercises); diff --git a/src/run.rs b/src/run.rs index e0ada4c5..aeb80dee 100644 --- a/src/run.rs +++ b/src/run.rs @@ -31,6 +31,21 @@ pub fn reset(exercise: &Exercise) -> Result<(), ()> { } } +//Resets all exercises by stashing the changes +pub fn reset_all(exercises: &[Exercise]) -> Result<(), ()> { + for exercise in exercises { + let command = Command::new("git") + .args(["stash", "push", "--"]) + .arg (&exercise.path) + .spawn(); + + if command.is_err() { + return Err(()); + } + } + Ok(()) +} + // Invoke the rust compiler on the path of the given exercise // and run the ensuing binary. // This is strictly for non-test binaries, so output is displayed