feat: stash all changes at once

This commit is contained in:
Dompeh Kofi Bright 2024-03-13 02:59:37 +00:00
parent 8d0aa11a35
commit 60d4735d11
2 changed files with 22 additions and 1 deletions

View file

@ -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);

View file

@ -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