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-08-26 16:12:59 +03:00
|
|
|
use super::utils::{self, Check, PathExt};
|
2018-08-19 14:45:23 +03:00
|
|
|
use directories::BaseDirs;
|
|
|
|
|
use failure::Error;
|
|
|
|
|
|
|
|
|
|
const EMACS_UPGRADE: &str = include_str!("emacs.el");
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
2018-08-26 16:12:59 +03:00
|
|
|
pub fn run_cargo_update(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
|
2018-08-19 14:45:23 +03:00
|
|
|
if let Some(cargo_update) = base_dirs.home_dir().join(".cargo/bin/cargo-install-update").if_exists() {
|
|
|
|
|
terminal.print_separator("Cargo");
|
|
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-08-26 16:12:59 +03:00
|
|
|
Executor::new(cargo_update, dry_run)
|
2018-08-19 14:45:23 +03:00
|
|
|
.args(&["install-update", "--git", "--all"])
|
|
|
|
|
.spawn()?
|
|
|
|
|
.wait()?
|
|
|
|
|
.check()?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}().is_ok();
|
|
|
|
|
|
|
|
|
|
return Some(("Cargo", success));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
2018-08-26 16:12:59 +03:00
|
|
|
pub fn run_emacs(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
|
2018-08-19 14:45:23 +03:00
|
|
|
if let Some(emacs) = utils::which("emacs") {
|
|
|
|
|
if let Some(init_file) = base_dirs.home_dir().join(".emacs.d/init.el").if_exists() {
|
|
|
|
|
terminal.print_separator("Emacs");
|
|
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-08-26 16:12:59 +03:00
|
|
|
Executor::new(&emacs, dry_run)
|
2018-08-19 14:45:23 +03:00
|
|
|
.args(&["--batch", "-l", init_file.to_str().unwrap(), "--eval", EMACS_UPGRADE])
|
|
|
|
|
.spawn()?
|
|
|
|
|
.wait()?
|
|
|
|
|
.check()?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}().is_ok();
|
|
|
|
|
|
|
|
|
|
return Some(("Emacs", success));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
2018-08-26 16:12:59 +03:00
|
|
|
pub fn run_apm(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
|
2018-08-19 14:45:23 +03:00
|
|
|
if let Some(apm) = utils::which("apm") {
|
|
|
|
|
terminal.print_separator("Atom Package Manager");
|
|
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-08-26 16:12:59 +03:00
|
|
|
Executor::new(&apm, dry_run)
|
2018-08-19 14:45:23 +03:00
|
|
|
.args(&["upgrade", "--confirm=false"])
|
|
|
|
|
.spawn()?
|
|
|
|
|
.wait()?
|
|
|
|
|
.check()?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}().is_ok();
|
|
|
|
|
|
|
|
|
|
return Some(("apm", success));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
2018-08-26 16:12:59 +03:00
|
|
|
pub fn run_rustup(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
|
2018-08-19 14:45:23 +03:00
|
|
|
if let Some(rustup) = utils::which("rustup") {
|
|
|
|
|
terminal.print_separator("rustup");
|
|
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
|
|
|
|
if rustup.is_descendant_of(base_dirs.home_dir()) {
|
2018-08-26 16:12:59 +03:00
|
|
|
Executor::new(&rustup, dry_run)
|
2018-08-19 14:45:23 +03:00
|
|
|
.args(&["self", "update"])
|
|
|
|
|
.spawn()?
|
|
|
|
|
.wait()?
|
|
|
|
|
.check()?;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-26 16:12:59 +03:00
|
|
|
Executor::new(&rustup, dry_run).arg("update").spawn()?.wait()?.check()?;
|
2018-08-19 14:45:23 +03:00
|
|
|
Ok(())
|
|
|
|
|
}().is_ok();
|
|
|
|
|
|
|
|
|
|
return Some(("rustup", success));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
2018-08-26 16:12:59 +03:00
|
|
|
pub fn run_custom_command(name: &str, command: &str, terminal: &mut Terminal, dry_run: bool) -> Result<(), Error> {
|
2018-08-19 14:45:23 +03:00
|
|
|
terminal.print_separator(name);
|
2018-08-26 16:12:59 +03:00
|
|
|
Executor::new("sh", dry_run)
|
|
|
|
|
.arg("-c")
|
|
|
|
|
.arg(command)
|
|
|
|
|
.spawn()?
|
|
|
|
|
.wait()?
|
|
|
|
|
.check()?;
|
2018-08-19 14:45:23 +03:00
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|