1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-07-03 00:46:57 +02:00

Improve resetting

This commit is contained in:
mo8it
2024-04-18 12:41:17 +02:00
parent f04089b8bc
commit 01e6732e4d
4 changed files with 67 additions and 47 deletions

View File

@ -1,17 +1,13 @@
use anyhow::{bail, Context, Result};
use anyhow::{Context, Result};
use crossterm::style::{style, StyledContent, Stylize};
use std::{
fmt::{self, Display, Formatter},
fs,
path::Path,
process::{Command, Output, Stdio},
process::{Command, Output},
};
use crate::{
embedded::{WriteStrategy, EMBEDDED_FILES},
info_file::Mode,
DEVELOPING_OFFICIAL_RUSTLINGS,
};
use crate::{info_file::Mode, DEVELOPING_OFFICIAL_RUSTLINGS};
pub struct TerminalFileLink<'a> {
path: &'a str,
@ -87,34 +83,6 @@ impl Exercise {
}
}
pub fn reset(&self) -> Result<()> {
if Path::new("info.toml").exists() {
let output = Command::new("git")
.arg("stash")
.arg("push")
.arg("--")
.arg(self.path)
.stdin(Stdio::null())
.stdout(Stdio::null())
.output()
.with_context(|| format!("Failed to run `git stash push -- {}`", self.path))?;
if !output.status.success() {
bail!(
"`git stash push -- {}` didn't run successfully: {}",
self.path,
String::from_utf8_lossy(&output.stderr),
);
}
} else {
EMBEDDED_FILES
.write_exercise_to_disk(self.path, WriteStrategy::Overwrite)
.with_context(|| format!("Failed to reset the exercise {self}"))?;
}
Ok(())
}
pub fn terminal_link(&self) -> StyledContent<TerminalFileLink<'_>> {
style(TerminalFileLink { path: self.path })
.underlined()