From 8472467d003f3efffafa9ac5d5851afdd2199b05 Mon Sep 17 00:00:00 2001 From: DottoDev <37108907+DottoDev@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:17:50 +0000 Subject: [PATCH] brew autoremove (#6) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authored-by: Kilian Tyler Approved-by: Thomas Schönauer --- config.example.toml | 1 + src/config.rs | 10 ++++++++++ src/steps/os/unix.rs | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/config.example.toml b/config.example.toml index 8ed8bdbe..5cc7eaea 100644 --- a/config.example.toml +++ b/config.example.toml @@ -64,6 +64,7 @@ [brew] #greedy_cask = true +#autoremove = true [linux] # Arch Package Manager to use. Allowed values: autodetect, trizen, paru, yay, pikaur, pacman, pamac. diff --git a/src/config.rs b/src/config.rs index 79fc9c33..fcfdcdee 100644 --- a/src/config.rs +++ b/src/config.rs @@ -202,6 +202,7 @@ pub struct Flatpak { #[serde(deny_unknown_fields)] pub struct Brew { greedy_cask: Option, + autoremove: Option, } #[derive(Debug, Deserialize, Clone, Copy)] @@ -668,6 +669,15 @@ impl Config { .unwrap_or(false) } + /// Whether Brew should autoremove + pub fn brew_autoremove(&self) -> bool { + self.config_file + .brew + .as_ref() + .and_then(|c| c.autoremove) + .unwrap_or(false) + } + /// Whether Composer should update itself pub fn composer_self_update(&self) -> bool { self.config_file diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index 377d9ae8..540d2ad3 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -210,6 +210,10 @@ pub fn run_brew_formula(ctx: &ExecutionContext, variant: BrewVariant) -> Result< variant.execute(run_type).arg("cleanup").check_run()?; } + if ctx.config().brew_autoremove() { + variant.execute(run_type).arg("autoremove").check_run()?; + } + Ok(()) }