pub mod vcs {
use std::path::Path;
use std::{fs::remove_dir_all, process::Command};
pub struct Hg {
repository: String,
url: String,
}
impl Hg {
pub fn new(uri: &str, repo: &str) -> Hg {
Self {
repository: repo.to_string(),
url: uri.to_string(),
}
.get()
}
fn get(self) -> Hg {
if Path::new(self.repository.as_str()).is_dir() {
remove_dir_all(self.repository.as_str())
.expect("failed to remove the last repository");
}
assert!(Command::new("hg")
.arg("clone")
.arg(self.url.as_str())
.arg(self.repository.as_str())
.spawn()
.expect("Failed to clone repository")
.wait()
.expect("msg")
.success());
self
}
pub fn run(&mut self, command: &mut Command) -> &mut Hg {
command
.current_dir(self.repository.as_str())
.spawn()
.expect("failed")
.wait()
.expect("");
self
}
pub fn clean(&mut self) -> bool {
remove_dir_all(self.repository.as_str()).expect("Failed to remove the directory");
true
}
}
}