2019-01-01 22:22:07 +02:00
|
|
|
use crate::error::Error;
|
|
|
|
|
use crate::executor::{CommandExt, RunType};
|
2018-12-15 21:52:21 +02:00
|
|
|
use crate::terminal::print_separator;
|
2019-01-01 22:22:07 +02:00
|
|
|
use crate::utils::{self, PathExt};
|
2018-08-19 14:45:23 +03:00
|
|
|
use directories::BaseDirs;
|
2018-10-02 13:45:29 +03:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
use std::process::Command;
|
2018-08-19 14:45:23 +03:00
|
|
|
|
|
|
|
|
const EMACS_UPGRADE: &str = include_str!("emacs.el");
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_cargo_update(run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-11-02 16:31:49 +02:00
|
|
|
if let Some(cargo_update) = utils::which("cargo-install-update") {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("Cargo");
|
2018-08-19 14:45:23 +03:00
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-12-31 13:26:17 +02:00
|
|
|
run_type
|
|
|
|
|
.execute(cargo_update)
|
2018-08-19 14:45:23 +03:00
|
|
|
.args(&["install-update", "--git", "--all"])
|
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-08-19 14:45:23 +03:00
|
|
|
|
|
|
|
|
return Some(("Cargo", success));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 16:46:49 +03:00
|
|
|
#[must_use]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_gem(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-09-06 16:46:49 +03:00
|
|
|
if let Some(gem) = utils::which("gem") {
|
|
|
|
|
if base_dirs.home_dir().join(".gem").exists() {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("RubyGems");
|
2018-09-06 16:46:49 +03:00
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&gem).args(&["update", "--user-install"]).check_run()?;
|
2018-09-06 16:46:49 +03:00
|
|
|
|
|
|
|
|
Ok(())
|
2018-12-11 16:00:19 +02:00
|
|
|
}()
|
|
|
|
|
.is_ok();
|
2018-09-06 16:46:49 +03:00
|
|
|
|
|
|
|
|
return Some(("RubyGems", success));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-19 14:45:23 +03:00
|
|
|
#[must_use]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_emacs(base_dirs: &BaseDirs, run_type: RunType) -> 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() {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("Emacs");
|
2018-08-19 14:45:23 +03:00
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-12-31 13:26:17 +02:00
|
|
|
run_type
|
|
|
|
|
.execute(&emacs)
|
2018-10-04 11:40:29 +03:00
|
|
|
.args(&["--batch", "-l", init_file.to_str().unwrap(), "--eval", EMACS_UPGRADE])
|
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-08-19 14:45:23 +03:00
|
|
|
|
|
|
|
|
return Some(("Emacs", success));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
2018-10-29 14:32:33 +02:00
|
|
|
#[cfg(not(any(
|
|
|
|
|
target_os = "freebsd",
|
|
|
|
|
target_os = "openbsd",
|
|
|
|
|
target_os = "netbsd",
|
|
|
|
|
target_os = "dragonfly"
|
|
|
|
|
)))]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_apm(run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-08-19 14:45:23 +03:00
|
|
|
if let Some(apm) = utils::which("apm") {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("Atom Package Manager");
|
2018-08-19 14:45:23 +03:00
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-12-31 13:26:17 +02:00
|
|
|
run_type
|
|
|
|
|
.execute(&apm)
|
2018-08-19 14:45:23 +03:00
|
|
|
.args(&["upgrade", "--confirm=false"])
|
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-08-19 14:45:23 +03:00
|
|
|
|
|
|
|
|
return Some(("apm", success));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[must_use]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_rustup(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-08-19 14:45:23 +03:00
|
|
|
if let Some(rustup) = utils::which("rustup") {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("rustup");
|
2018-08-19 14:45:23 +03:00
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
|
|
|
|
if rustup.is_descendant_of(base_dirs.home_dir()) {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&rustup).args(&["self", "update"]).check_run()?;
|
2018-08-19 14:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&rustup).arg("update").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
|
|
|
|
|
|
|
|
return Some(("rustup", success));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-18 16:05:27 +03:00
|
|
|
#[must_use]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_jetpack(run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-10-18 16:05:27 +03:00
|
|
|
if let Some(jetpack) = utils::which("jetpack") {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("Jetpack");
|
2018-10-18 16:05:27 +03:00
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&jetpack).args(&["global", "update"]).check_run()?;
|
2018-10-18 16:05:27 +03:00
|
|
|
Ok(())
|
2018-12-11 16:00:19 +02:00
|
|
|
}()
|
|
|
|
|
.is_ok();
|
2018-10-18 16:05:27 +03:00
|
|
|
|
|
|
|
|
return Some(("Jetpack", success));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 13:45:01 +02:00
|
|
|
#[must_use]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_opam_update(run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-09-03 13:45:01 +02:00
|
|
|
if let Some(opam) = utils::which("opam") {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("OCaml Package Manager");
|
2018-09-03 13:45:01 +02:00
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&opam).arg("update").check_run()?;
|
|
|
|
|
run_type.execute(&opam).arg("upgrade").check_run()?;
|
2018-09-03 13:45:01 +02:00
|
|
|
Ok(())
|
2018-12-11 16:00:19 +02:00
|
|
|
}()
|
|
|
|
|
.is_ok();
|
2018-09-03 13:45:01 +02:00
|
|
|
|
|
|
|
|
return Some(("OPAM", success));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-10 20:22:26 +02:00
|
|
|
#[must_use]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_vcpkg_update(run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-11-10 20:22:26 +02:00
|
|
|
if let Some(vcpkg) = utils::which("vcpkg") {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("vcpkg");
|
2018-11-10 20:22:26 +02:00
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-12-31 13:26:17 +02:00
|
|
|
run_type
|
|
|
|
|
.execute(&vcpkg)
|
2018-12-05 11:34:08 +02:00
|
|
|
.args(&["upgrade", "--no-dry-run"])
|
2018-12-31 22:00:34 +02:00
|
|
|
.check_run()?;
|
2018-11-10 20:22:26 +02:00
|
|
|
Ok(())
|
2018-12-11 16:00:19 +02:00
|
|
|
}()
|
|
|
|
|
.is_ok();
|
2018-11-10 20:22:26 +02:00
|
|
|
|
|
|
|
|
return Some(("vcpkg", success));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-31 13:01:57 +02:00
|
|
|
#[must_use]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_pipx_update(run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-10-31 13:01:57 +02:00
|
|
|
if let Some(pipx) = utils::which("pipx") {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("pipx");
|
2018-10-31 13:01:57 +02:00
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&pipx).arg("upgrade-all").check_run()?;
|
2018-10-31 13:01:57 +02:00
|
|
|
Ok(())
|
2018-12-11 16:00:19 +02:00
|
|
|
}()
|
|
|
|
|
.is_ok();
|
2018-10-31 13:01:57 +02:00
|
|
|
|
|
|
|
|
return Some(("pipx", success));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-19 14:45:23 +03:00
|
|
|
#[must_use]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_custom_command(name: &str, command: &str, run_type: RunType) -> Result<(), Error> {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator(name);
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute("sh").arg("-c").arg(command).check_run()?;
|
2018-08-19 14:45:23 +03:00
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2018-10-02 13:45:29 +03:00
|
|
|
|
|
|
|
|
#[must_use]
|
2018-12-31 13:26:17 +02:00
|
|
|
pub fn run_composer_update(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> {
|
2018-10-02 13:45:29 +03:00
|
|
|
if let Some(composer) = utils::which("composer") {
|
2019-01-01 22:22:07 +02:00
|
|
|
let composer_home = Command::new(&composer)
|
|
|
|
|
.args(&["global", "config", "--absolute", "home"])
|
|
|
|
|
.check_output()
|
|
|
|
|
.map(PathBuf::from);
|
2018-10-02 13:45:29 +03:00
|
|
|
|
|
|
|
|
if let Ok(composer_home) = composer_home {
|
|
|
|
|
if composer_home.is_descendant_of(base_dirs.home_dir()) {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("Composer");
|
2018-10-02 13:45:29 +03:00
|
|
|
|
|
|
|
|
let success = || -> Result<(), Error> {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&composer).args(&["global", "update"]).check_run()?;
|
2018-12-17 10:53:05 +02:00
|
|
|
|
|
|
|
|
if let Some(valet) = utils::which("valet") {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&valet).arg("install").check_run()?;
|
2018-12-17 10:53:05 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-02 13:45:29 +03:00
|
|
|
Ok(())
|
2018-12-11 16:00:19 +02:00
|
|
|
}()
|
|
|
|
|
.is_ok();
|
2018-10-02 13:45:29 +03:00
|
|
|
|
|
|
|
|
return Some(("Composer", success));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None
|
|
|
|
|
}
|