Files
topgrade/src/unix.rs

70 lines
2.1 KiB
Rust
Raw Normal View History

2018-08-26 16:12:59 +03:00
use super::executor::Executor;
2018-08-19 14:45:23 +03:00
use super::terminal::Terminal;
2018-09-04 11:05:54 +03:00
use super::utils::{which, Check};
2018-07-07 09:18:53 +03:00
use directories::BaseDirs;
2018-08-19 14:45:23 +03:00
use failure::Error;
2018-06-28 12:16:54 +03:00
2018-08-26 16:12:59 +03:00
pub fn run_zplug(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> 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() {
terminal.print_separator("zplug");
2018-06-28 12:16:54 +03:00
2018-08-19 14:45:23 +03:00
let success = || -> Result<(), Error> {
2018-08-26 16:12:59 +03:00
Executor::new(zsh, dry_run)
2018-08-19 14:45:23 +03:00
.args(&["-c", "source ~/.zshrc && zplug update"])
.spawn()?
.wait()?
.check()?;
Ok(())
}().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-10-07 11:51:12 +03:00
pub fn run_fisher(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> 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-10-07 11:51:12 +03:00
terminal.print_separator("fisher");
2018-08-19 14:45:23 +03:00
let success = || -> Result<(), Error> {
2018-10-07 11:51:12 +03:00
Executor::new(&fish, dry_run)
.args(&["-c", "fisher self-update"])
.spawn()?
.wait()?
.check()?;
Executor::new(&fish, dry_run)
2018-10-06 19:43:21 +03:00
.args(&["-c", "fisher"])
2018-08-19 14:45:23 +03:00
.spawn()?
.wait()?
.check()?;
Ok(())
}().is_ok();
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-08-26 16:12:59 +03:00
pub fn run_homebrew(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
2018-08-19 14:45:23 +03:00
if let Some(brew) = which("brew") {
terminal.print_separator("Brew");
let inner = || -> Result<(), Error> {
2018-08-26 16:12:59 +03:00
Executor::new(&brew, dry_run).arg("update").spawn()?.wait()?.check()?;
Executor::new(&brew, dry_run).arg("upgrade").spawn()?.wait()?.check()?;
2018-08-19 14:45:23 +03:00
Ok(())
};
return Some(("Brew", inner().is_ok()));
}
None
}