Adding a new flag for cleaning up old resources (#90)

* Adding a new flag to topgrade called "cleanup"

If you are using applications like homebrew they may keep a history of
packages downloaded. Especially the bigger your number of installed
packages for homebrew grows the bigger those directories get. This can
quickly add up to a couple of GBs.

If this flag is set then the homebrew part also calls "brew cleanup" for
cleaning up old resources. Of course this can be add to other calls as
well if supported.

* Updating readme for new cleanup flag
This commit is contained in:
Nikolai Hellwig
2018-11-17 19:09:46 +01:00
committed by Roey Darwish Dror
parent b370955f79
commit 7e5eb87b7d
4 changed files with 9 additions and 2 deletions

View File

@@ -87,6 +87,7 @@ Just run `topgrade`. It will run the following steps:
## Flags ## Flags
* `-t/--tmux` - Topgrade will launch itself in a new tmux session. This flag has no effect if * `-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. 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. * `-n/--dry-run` - Print what should be run.
* `--no-system` - Skip the system upgrade phase. * `--no-system` - Skip the system upgrade phase.
* `--no-git-repos` - Don't pull custom git repositories. * `--no-git-repos` - Don't pull custom git repositories.

View File

@@ -51,6 +51,9 @@ pub struct Opt {
#[structopt(short = "t", long = "tmux", help = "Run inside tmux")] #[structopt(short = "t", long = "tmux", help = "Run inside tmux")]
pub run_in_tmux: bool, 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")] #[structopt(long = "no-system", help = "Don't perform system upgrade")]
pub no_system: bool, pub no_system: bool,

View File

@@ -240,7 +240,7 @@ fn run() -> Result<(), Error> {
#[cfg(unix)] #[cfg(unix)]
report.push_result(execute( 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, &mut execution_context,
)?); )?);
#[cfg(target_os = "freebsd")] #[cfg(target_os = "freebsd")]

View File

@@ -52,13 +52,16 @@ pub fn run_fisher(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool)
} }
#[must_use] #[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") { if let Some(brew) = which("brew") {
terminal.print_separator("Brew"); terminal.print_separator("Brew");
let inner = || -> Result<(), Error> { let inner = || -> Result<(), Error> {
Executor::new(&brew, dry_run).arg("update").spawn()?.wait()?.check()?; Executor::new(&brew, dry_run).arg("update").spawn()?.wait()?.check()?;
Executor::new(&brew, dry_run).arg("upgrade").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(()) Ok(())
}; };