Skip to content

Commit

Permalink
implode|prune: support --yes
Browse files Browse the repository at this point in the history
Fixes #982
  • Loading branch information
jdx committed Nov 8, 2023
1 parent 231e1d0 commit ea5b5d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 19 additions & 6 deletions src/cli/implode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use color_eyre::eyre::Result;
use std::path::Path;

use crate::cli::command::Command;
use crate::config::Config;
Expand All @@ -23,7 +24,7 @@ pub struct Implode {
}

impl Command for Implode {
fn run(self, _config: Config, out: &mut Output) -> Result<()> {
fn run(self, config: Config, out: &mut Output) -> Result<()> {
let mut files = vec![&*dirs::ROOT, &*dirs::CACHE, &*env::RTX_EXE];
if self.config {
files.push(&*dirs::CONFIG);
Expand All @@ -33,20 +34,32 @@ impl Command for Implode {
rtxprintln!(out, "rm -rf {}", f.display());
}

if f.is_dir() {
if !self.dry_run && prompt::confirm(&format!("remove {} ?", f.display()))? {
if self.confirm_remove(&config, f)? {
if f.is_dir() {
remove_all(f)?;
return Ok(());
} else {
file::remove_file(f)?;
}
} else if !self.dry_run && prompt::confirm(&format!("remove {} ?", f.display()))? {
file::remove_file(f)?;
}
}

Ok(())
}
}

impl Implode {
fn confirm_remove(&self, config: &Config, f: &Path) -> Result<bool> {
if self.dry_run {
Ok(false)
} else if config.settings.yes {
Ok(true)
} else {
let r = prompt::confirm(&format!("remove {} ?", f.display()))?;
Ok(r)
}
}
}

#[cfg(test)]
#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Prune {
if self.dry_run {
pr.set_prefix(format!("{} {} ", pr.prefix(), style("[dryrun]").bold()));
}
if prompt::confirm(&format!("remove {} ?", &tv))? {
if config.settings.yes || prompt::confirm(&format!("remove {} ?", &tv))? {
p.decorate_progress_bar(&mut pr, Some(&tv));
p.uninstall_version(config, &tv, &pr, self.dry_run)?;
pr.finish();
Expand Down

0 comments on commit ea5b5d6

Please sign in to comment.