Add a configuration variable for greedy cask (fix #401)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -51,6 +51,11 @@ pub enum Step {
|
||||
Tmux,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default, Debug)]
|
||||
pub struct Brew {
|
||||
greedy_cask: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default, Debug)]
|
||||
pub struct Composer {
|
||||
self_update: Option<bool>,
|
||||
@@ -79,6 +84,7 @@ pub struct ConfigFile {
|
||||
accept_all_windows_updates: Option<bool>,
|
||||
only: Option<Vec<Step>>,
|
||||
composer: Option<Composer>,
|
||||
brew: Option<Brew>,
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -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))?;
|
||||
|
||||
@@ -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()?;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user