diff --git a/README.md b/README.md index 53394972..d34ce7b8 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ Just run `topgrade`. It will run the following steps: ## Flags * `-t/--tmux` - Topgrade will launch itself in a new tmux session. This flag has no effect if Topgrade already runs inside tmux. This is useful when using topgrade on remote systems. +* `-c/--cleanup` - Topgrade will instruct package managers to remove old or unused files * `-n/--dry-run` - Print what should be run. * `--no-system` - Skip the system upgrade phase. * `--no-git-repos` - Don't pull custom git repositories. diff --git a/src/config.rs b/src/config.rs index 33531b1f..73896386 100644 --- a/src/config.rs +++ b/src/config.rs @@ -51,6 +51,9 @@ pub struct Opt { #[structopt(short = "t", long = "tmux", help = "Run inside tmux")] pub run_in_tmux: bool, + #[structopt(short = "c", long = "cleanup", help = "Cleanup temporary or old files")] + pub cleanup: bool, + #[structopt(long = "no-system", help = "Don't perform system upgrade")] pub no_system: bool, diff --git a/src/main.rs b/src/main.rs index bc41d3cf..39fbf3a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -240,7 +240,7 @@ fn run() -> Result<(), Error> { #[cfg(unix)] report.push_result(execute( - |terminal| unix::run_homebrew(terminal, opt.dry_run), + |terminal| unix::run_homebrew(terminal, opt.cleanup, opt.dry_run), &mut execution_context, )?); #[cfg(target_os = "freebsd")] diff --git a/src/unix.rs b/src/unix.rs index fa25e969..e1754049 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -52,13 +52,16 @@ pub fn run_fisher(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) } #[must_use] -pub fn run_homebrew(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { +pub fn run_homebrew(terminal: &mut Terminal, cleanup: bool, dry_run: bool) -> Option<(&'static str, bool)> { if let Some(brew) = which("brew") { terminal.print_separator("Brew"); let inner = || -> Result<(), Error> { Executor::new(&brew, dry_run).arg("update").spawn()?.wait()?.check()?; Executor::new(&brew, dry_run).arg("upgrade").spawn()?.wait()?.check()?; + if cleanup { + Executor::new(&brew, dry_run).arg("cleanup").spawn()?.wait()?.check()?; + } Ok(()) };