Add a configuration variable for greedy cask (fix #401)
This commit is contained in:
@@ -53,3 +53,6 @@
|
|||||||
# Custom commands
|
# Custom commands
|
||||||
#[commands]
|
#[commands]
|
||||||
#"Python Environment" = "~/dev/.env/bin/pip install -i https://pypi.python.org/simple -U --upgrade-strategy eager jupyter"
|
#"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,
|
Tmux,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Default, Debug)]
|
||||||
|
pub struct Brew {
|
||||||
|
greedy_cask: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Default, Debug)]
|
#[derive(Deserialize, Default, Debug)]
|
||||||
pub struct Composer {
|
pub struct Composer {
|
||||||
self_update: Option<bool>,
|
self_update: Option<bool>,
|
||||||
@@ -79,6 +84,7 @@ pub struct ConfigFile {
|
|||||||
accept_all_windows_updates: Option<bool>,
|
accept_all_windows_updates: Option<bool>,
|
||||||
only: Option<Vec<Step>>,
|
only: Option<Vec<Step>>,
|
||||||
composer: Option<Composer>,
|
composer: Option<Composer>,
|
||||||
|
brew: Option<Brew>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConfigFile {
|
impl ConfigFile {
|
||||||
@@ -366,6 +372,15 @@ impl Config {
|
|||||||
self.config_file.accept_all_windows_updates.unwrap_or(true)
|
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
|
/// Whether Composer should update itself
|
||||||
pub fn composer_self_update(&self) -> bool {
|
pub fn composer_self_update(&self) -> bool {
|
||||||
self.config_file
|
self.config_file
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ fn run() -> Result<()> {
|
|||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
if config.should_run(Step::PackageManagers) {
|
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")]
|
#[cfg(target_os = "macos")]
|
||||||
runner.execute("MacPorts", || macos::run_macports(&ctx))?;
|
runner.execute("MacPorts", || macos::run_macports(&ctx))?;
|
||||||
runner.execute("nix", || unix::run_nix(&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()
|
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")?;
|
let brew = require("brew")?;
|
||||||
print_separator("Brew");
|
print_separator("Brew");
|
||||||
|
let run_type = ctx.run_type();
|
||||||
|
let config = ctx.config();
|
||||||
|
|
||||||
run_type.execute(&brew).arg("update").check_run()?;
|
run_type.execute(&brew).arg("update").check_run()?;
|
||||||
run_type
|
run_type
|
||||||
@@ -45,13 +47,22 @@ pub fn run_homebrew(cleanup: bool, run_type: RunType) -> Result<()> {
|
|||||||
.check_output()
|
.check_output()
|
||||||
.map(|p| Path::new(p.trim()).exists())?;
|
.map(|p| Path::new(p.trim()).exists())?;
|
||||||
|
|
||||||
if cask_upgrade_exists {
|
let cask_args = if cask_upgrade_exists {
|
||||||
run_type.execute(&brew).args(&["cu", "-ay"]).check_run()?;
|
let mut args = vec!["cu", "-y"];
|
||||||
} else {
|
if config.brew_cask_greedy() {
|
||||||
run_type.execute(&brew).args(&["cask", "upgrade"]).check_run()?;
|
args.push("-a");
|
||||||
}
|
}
|
||||||
|
args
|
||||||
|
} else {
|
||||||
|
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()?;
|
run_type.execute(&brew).arg("cleanup").check_run()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user