From 5060451066093d2b46b20afd55c575ddbfbca21f Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Tue, 12 May 2020 09:07:54 +0300 Subject: [PATCH] Add a configuration variable for greedy cask (fix #401) --- config.example.toml | 3 +++ src/config.rs | 15 +++++++++++++++ src/main.rs | 2 +- src/steps/os/unix.rs | 23 +++++++++++++++++------ 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/config.example.toml b/config.example.toml index 9679e9a3..28474b96 100644 --- a/config.example.toml +++ b/config.example.toml @@ -53,3 +53,6 @@ # Custom commands #[commands] #"Python Environment" = "~/dev/.env/bin/pip install -i https://pypi.python.org/simple -U --upgrade-strategy eager jupyter" + +#[brew] +#greedy_cask = true diff --git a/src/config.rs b/src/config.rs index 30804c26..e7cb6acc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -51,6 +51,11 @@ pub enum Step { Tmux, } +#[derive(Deserialize, Default, Debug)] +pub struct Brew { + greedy_cask: Option, +} + #[derive(Deserialize, Default, Debug)] pub struct Composer { self_update: Option, @@ -79,6 +84,7 @@ pub struct ConfigFile { accept_all_windows_updates: Option, only: Option>, composer: Option, + brew: Option, } impl ConfigFile { @@ -366,6 +372,15 @@ impl Config { self.config_file.accept_all_windows_updates.unwrap_or(true) } + /// Whether Brew cask should be greedy + pub fn brew_cask_greedy(&self) -> bool { + self.config_file + .brew + .as_ref() + .and_then(|c| c.greedy_cask) + .unwrap_or(false) + } + /// Whether Composer should update itself pub fn composer_self_update(&self) -> bool { self.config_file diff --git a/src/main.rs b/src/main.rs index 5ab559c0..b3fb06c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,7 +141,7 @@ fn run() -> Result<()> { #[cfg(unix)] { if config.should_run(Step::PackageManagers) { - runner.execute("brew", || unix::run_homebrew(config.cleanup(), run_type))?; + runner.execute("brew", || unix::run_homebrew(&ctx))?; #[cfg(target_os = "macos")] runner.execute("MacPorts", || macos::run_macports(&ctx))?; runner.execute("nix", || unix::run_nix(&ctx))?; diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index 63d1092a..182a3d40 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -30,9 +30,11 @@ pub fn run_fisher(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> { run_type.execute(&fish).args(&["-c", "fisher"]).check_run() } -pub fn run_homebrew(cleanup: bool, run_type: RunType) -> Result<()> { +pub fn run_homebrew(ctx: &ExecutionContext) -> Result<()> { let brew = require("brew")?; print_separator("Brew"); + let run_type = ctx.run_type(); + let config = ctx.config(); run_type.execute(&brew).arg("update").check_run()?; run_type @@ -45,13 +47,22 @@ pub fn run_homebrew(cleanup: bool, run_type: RunType) -> Result<()> { .check_output() .map(|p| Path::new(p.trim()).exists())?; - if cask_upgrade_exists { - run_type.execute(&brew).args(&["cu", "-ay"]).check_run()?; + let cask_args = if cask_upgrade_exists { + let mut args = vec!["cu", "-y"]; + if config.brew_cask_greedy() { + args.push("-a"); + } + args } else { - run_type.execute(&brew).args(&["cask", "upgrade"]).check_run()?; - } + let mut args = vec!["cask", "upgrade"]; + if config.brew_cask_greedy() { + args.push("--greedy"); + } + args + }; + run_type.execute(&brew).args(&cask_args).check_run()?; - if cleanup { + if ctx.config().cleanup() { run_type.execute(&brew).arg("cleanup").check_run()?; }