This commit is contained in:
kekeli 2024-03-15 14:20:56 +00:00 committed by GitHub
commit 8cb29fc2a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 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, reset_all, run};
use crate::verify::verify;
use clap::{Parser, Subcommand};
use console::Emoji;
@ -56,6 +56,7 @@ enum Subcommands {
/// The name of the exercise
name: String,
},
ResetAll {},
/// Return a hint for the given exercise
Hint {
/// The name of the exercise
@ -184,6 +185,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