2018-12-15 21:52:21 +02:00
|
|
|
use crate::error::Error;
|
2018-12-31 13:26:17 +02:00
|
|
|
use crate::executor::RunType;
|
2018-12-15 21:52:21 +02:00
|
|
|
use crate::terminal::print_separator;
|
2018-12-31 22:00:34 +02:00
|
|
|
use crate::utils::which;
|
2018-07-07 09:18:53 +03:00
|
|
|
use directories::BaseDirs;
|
2018-06-28 12:16:54 +03:00
|
|
|
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-08-19 14:45:23 +03:00
|
|
|
if let Some(zsh) = which("zsh") {
|
|
|
|
|
if base_dirs.home_dir().join(".zplug").exists() {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("zplug");
|
2018-06-28 12:16:54 +03:00
|
|
|
|
2018-08-19 14:45:23 +03:00
|
|
|
let success = || -> Result<(), Error> {
|
2018-12-31 13:26:17 +02:00
|
|
|
run_type
|
|
|
|
|
.execute(zsh)
|
2018-08-19 14:45:23 +03:00
|
|
|
.args(&["-c", "source ~/.zshrc && zplug update"])
|
2018-12-31 22:00:34 +02:00
|
|
|
.check_run()?;
|
2018-08-19 14:45:23 +03:00
|
|
|
Ok(())
|
2018-12-11 16:00:19 +02:00
|
|
|
}()
|
|
|
|
|
.is_ok();
|
2018-06-28 12:16:54 +03:00
|
|
|
|
2018-08-19 14:45:23 +03:00
|
|
|
return Some(("zplug", success));
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-03 14:31:25 +03:00
|
|
|
|
2018-08-19 14:45:23 +03:00
|
|
|
None
|
2018-07-03 14:31:25 +03:00
|
|
|
}
|
|
|
|
|
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_fisher(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-08-26 16:53:19 +03:00
|
|
|
if let Some(fish) = which("fish") {
|
2018-08-19 14:45:23 +03:00
|
|
|
if base_dirs.home_dir().join(".config/fish/functions/fisher.fish").exists() {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("fisher");
|
2018-08-19 14:45:23 +03:00
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-12-31 13:26:17 +02:00
|
|
|
run_type
|
|
|
|
|
.execute(&fish)
|
2018-10-07 11:51:12 +03:00
|
|
|
.args(&["-c", "fisher self-update"])
|
2018-12-31 22:00:34 +02:00
|
|
|
.check_run()?;
|
|
|
|
|
run_type.execute(&fish).args(&["-c", "fisher"]).check_run()?;
|
2018-08-19 14:45:23 +03:00
|
|
|
Ok(())
|
2018-12-11 16:00:19 +02:00
|
|
|
}()
|
|
|
|
|
.is_ok();
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2018-10-07 11:51:12 +03:00
|
|
|
return Some(("fisher", success));
|
2018-08-19 14:45:23 +03:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-28 12:16:54 +03:00
|
|
|
|
2018-08-19 14:45:23 +03:00
|
|
|
None
|
2018-06-28 12:16:54 +03:00
|
|
|
}
|
|
|
|
|
|
2018-08-19 14:45:23 +03:00
|
|
|
#[must_use]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_homebrew(cleanup: bool, run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-08-19 14:45:23 +03:00
|
|
|
if let Some(brew) = which("brew") {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("Brew");
|
2018-08-19 14:45:23 +03:00
|
|
|
|
|
|
|
|
let inner = || -> Result<(), Error> {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&brew).arg("update").check_run()?;
|
|
|
|
|
run_type.execute(&brew).arg("upgrade").check_run()?;
|
|
|
|
|
run_type.execute(&brew).args(&["cask", "upgrade"]).check_run()?;
|
2018-11-17 19:09:46 +01:00
|
|
|
if cleanup {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&brew).arg("cleanup").check_run()?;
|
2018-11-17 19:09:46 +01:00
|
|
|
}
|
2018-08-19 14:45:23 +03:00
|
|
|
Ok(())
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Some(("Brew", inner().is_ok()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
2018-10-21 13:05:49 +03:00
|
|
|
|
|
|
|
|
#[must_use]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_nix(run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-10-21 13:05:49 +03:00
|
|
|
if let Some(nix) = which("nix") {
|
|
|
|
|
if let Some(nix_env) = which("nix-env") {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("Nix");
|
2018-10-21 13:05:49 +03:00
|
|
|
|
|
|
|
|
let inner = || -> Result<(), Error> {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&nix).arg("upgrade-nix").check_run()?;
|
|
|
|
|
run_type.execute(&nix_env).arg("--upgrade").check_run()?;
|
2018-10-21 13:05:49 +03:00
|
|
|
Ok(())
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Some(("Nix", inner().is_ok()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|