mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-01-14 00:00:02 +03:00
feat: stash all changes at once
This commit is contained in:
parent
8d0aa11a35
commit
60d4735d11
|
@ -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);
|
||||
|
|
15
src/run.rs
15
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
|
||||
|
|
Loading…
Reference in a new issue