diff --git a/src/project.rs b/src/project.rs index 06889d1..247dcff 100644 --- a/src/project.rs +++ b/src/project.rs @@ -13,9 +13,7 @@ use std::{ process::Command, }; -pub enum Project { - Temporary(tempfile::TempDir), -} +pub struct Project(tempfile::TempDir); impl Project { pub fn execute(cli: Cli, config: Config) -> Result<()> { @@ -26,7 +24,7 @@ impl Project { config.vcs.as_deref(), )?; - let project_path = project.path(); + let project_path = project.0.path(); let delete_file = project_path.join("TO_DELETE"); write( @@ -244,7 +242,7 @@ impl Project { )?; } - Ok(Self::Temporary(tmp_dir)) + Ok(Project(tmp_dir)) } fn clean_up( @@ -290,22 +288,17 @@ impl Project { let tmp_dir = self.preserve_dir(project_name, preserved_project_dir)?; log::info!("Project directory_preserved_at: {}", tmp_dir.display()); - } else { - match self { - Self::Temporary(tempdir) => { - if worktree_branch.is_some() { - let mut command = std::process::Command::new("git"); - command - .args(["worktree", "remove"]) - .arg(tempdir.path()) - .arg("--force"); - ensure!( - command.status().context("Could not start git")?.success(), - "cannot remove working tree" - ); - } - } - } + } else if worktree_branch.is_some() { + let mut command = std::process::Command::new("git"); + command + .args(["worktree", "remove"]) + .arg(self.0.path()) + .arg("--force"); + + ensure!( + command.status().context("Could not start git")?.success(), + "cannot remove working tree" + ); } kill_subprocesses(subprocesses) @@ -316,9 +309,7 @@ impl Project { project_name: Option<&str>, preserved_project_dir: Option<&Path>, ) -> Result { - let tmp_dir = match self { - Self::Temporary(tempdir) => tempdir.into_path(), - }; + let tmp_dir = self.0.into_path(); let mut final_dir = if let Some(preserved_project_dir) = preserved_project_dir { if !preserved_project_dir.exists() { @@ -345,10 +336,4 @@ impl Project { Ok(final_dir) } - - fn path(&self) -> &Path { - match self { - Self::Temporary(tempdir) => tempdir.path(), - } - } }