mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-27 00:00:03 +03:00
Inline reset
This commit is contained in:
parent
fb32d0b86f
commit
7560aec66b
|
@ -1,5 +1,6 @@
|
||||||
|
use crate::embedded::{WriteStrategy, EMBEDDED_FILES};
|
||||||
use crate::exercise::{Exercise, ExerciseList};
|
use crate::exercise::{Exercise, ExerciseList};
|
||||||
use crate::run::{reset, run};
|
use crate::run::run;
|
||||||
use crate::verify::verify;
|
use crate::verify::verify;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
@ -207,7 +208,9 @@ If you are just starting with Rustlings, run the command `rustlings init` to ini
|
||||||
|
|
||||||
Subcommands::Reset { name } => {
|
Subcommands::Reset { name } => {
|
||||||
let exercise = find_exercise(&name, &exercises)?;
|
let exercise = find_exercise(&name, &exercises)?;
|
||||||
reset(exercise)?;
|
EMBEDDED_FILES
|
||||||
|
.write_exercise_to_disk(&exercise.path, WriteStrategy::Overwrite)
|
||||||
|
.with_context(|| format!("Failed to reset the exercise {exercise}"))?;
|
||||||
println!("The file {} has been reset!", exercise.path.display());
|
println!("The file {} has been reset!", exercise.path.display());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
src/run.rs
11
src/run.rs
|
@ -1,8 +1,7 @@
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use std::io::{self, stdout, Write};
|
use std::io::{stdout, Write};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::embedded::{WriteStrategy, EMBEDDED_FILES};
|
|
||||||
use crate::exercise::{Exercise, Mode};
|
use crate::exercise::{Exercise, Mode};
|
||||||
use crate::verify::test;
|
use crate::verify::test;
|
||||||
use indicatif::ProgressBar;
|
use indicatif::ProgressBar;
|
||||||
|
@ -18,13 +17,7 @@ pub fn run(exercise: &Exercise, verbose: bool) -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resets the exercise by stashing the changes.
|
// Compile and run an exercise.
|
||||||
pub fn reset(exercise: &Exercise) -> io::Result<()> {
|
|
||||||
EMBEDDED_FILES.write_exercise_to_disk(&exercise.path, WriteStrategy::Overwrite)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
// This is strictly for non-test binaries, so output is displayed
|
||||||
fn compile_and_run(exercise: &Exercise) -> Result<()> {
|
fn compile_and_run(exercise: &Exercise) -> Result<()> {
|
||||||
let progress_bar = ProgressBar::new_spinner();
|
let progress_bar = ProgressBar::new_spinner();
|
||||||
|
|
Loading…
Reference in a new issue