2019-01-13 23:20:32 +02:00
|
|
|
use crate::error::{Error, ErrorKind};
|
2019-01-01 22:22:07 +02:00
|
|
|
use crate::executor::{CommandExt, RunType};
|
2019-08-22 21:46:06 +03:00
|
|
|
use crate::terminal::{print_separator, shell};
|
2019-01-01 22:22:07 +02:00
|
|
|
use crate::utils::{self, PathExt};
|
2018-08-19 14:45:23 +03:00
|
|
|
use directories::BaseDirs;
|
2019-02-12 19:50:00 +02:00
|
|
|
use failure::ResultExt;
|
2018-10-02 13:45:29 +03:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
use std::process::Command;
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
pub fn run_cargo_update(run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let cargo_update = utils::require("cargo-install-update")?;
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
print_separator("Cargo");
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
run_type
|
|
|
|
|
.execute(cargo_update)
|
|
|
|
|
.args(&["install-update", "--git", "--all"])
|
|
|
|
|
.check_run()
|
2018-08-19 14:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
pub fn run_gem(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let gem = utils::require("gem")?;
|
|
|
|
|
base_dirs.home_dir().join(".gem").require()?;
|
2018-09-06 16:46:49 +03:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
print_separator("RubyGems");
|
2018-09-06 16:46:49 +03:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
run_type.execute(&gem).args(&["update", "--user-install"]).check_run()
|
2018-09-06 16:46:49 +03:00
|
|
|
}
|
|
|
|
|
|
2018-10-29 14:32:33 +02:00
|
|
|
#[cfg(not(any(
|
|
|
|
|
target_os = "freebsd",
|
|
|
|
|
target_os = "openbsd",
|
|
|
|
|
target_os = "netbsd",
|
|
|
|
|
target_os = "dragonfly"
|
|
|
|
|
)))]
|
2019-01-13 23:20:32 +02:00
|
|
|
pub fn run_apm(run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let apm = utils::require("apm")?;
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
print_separator("Atom Package Manager");
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
run_type.execute(&apm).args(&["upgrade", "--confirm=false"]).check_run()
|
2018-08-19 14:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
pub fn run_rustup(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let rustup = utils::require("rustup")?;
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
print_separator("rustup");
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2019-02-12 19:50:00 +02:00
|
|
|
if rustup
|
|
|
|
|
.canonicalize()
|
|
|
|
|
.context(ErrorKind::StepFailed)?
|
|
|
|
|
.is_descendant_of(base_dirs.home_dir())
|
|
|
|
|
{
|
2019-01-13 23:20:32 +02:00
|
|
|
run_type.execute(&rustup).args(&["self", "update"]).check_run()?;
|
2018-08-19 14:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
run_type.execute(&rustup).arg("update").check_run()
|
2018-08-19 14:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
pub fn run_jetpack(run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let jetpack = utils::require("jetpack")?;
|
2018-10-18 16:05:27 +03:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
print_separator("Jetpack");
|
2018-10-18 16:05:27 +03:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
run_type.execute(&jetpack).args(&["global", "update"]).check_run()
|
2018-10-18 16:05:27 +03:00
|
|
|
}
|
|
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
pub fn run_opam_update(run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let opam = utils::require("opam")?;
|
2018-09-03 13:45:01 +02:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
print_separator("OCaml Package Manager");
|
2018-09-03 13:45:01 +02:00
|
|
|
|
2019-01-13 23:20:32 +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
|
|
|
}
|
|
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
pub fn run_vcpkg_update(run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let vcpkg = utils::require("vcpkg")?;
|
|
|
|
|
print_separator("vcpkg");
|
2018-11-10 20:22:26 +02:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
run_type.execute(&vcpkg).args(&["upgrade", "--no-dry-run"]).check_run()
|
2018-11-10 20:22:26 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
pub fn run_pipx_update(run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let pipx = utils::require("pipx")?;
|
|
|
|
|
print_separator("pipx");
|
2018-10-31 13:01:57 +02:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
run_type.execute(&pipx).arg("upgrade-all").check_run()
|
2018-10-31 13:01:57 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-15 11:33:22 +02:00
|
|
|
pub fn run_myrepos_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let myrepos = utils::require("mr")?;
|
|
|
|
|
base_dirs.home_dir().join(".mrconfig").require()?;
|
|
|
|
|
|
|
|
|
|
print_separator("myrepos");
|
|
|
|
|
|
|
|
|
|
run_type
|
|
|
|
|
.execute(&myrepos)
|
|
|
|
|
.arg("--directory")
|
|
|
|
|
.arg(base_dirs.home_dir())
|
|
|
|
|
.arg("checkout")
|
|
|
|
|
.check_run()?;
|
|
|
|
|
run_type
|
|
|
|
|
.execute(&myrepos)
|
|
|
|
|
.arg("--directory")
|
|
|
|
|
.arg(base_dirs.home_dir())
|
|
|
|
|
.arg("update")
|
|
|
|
|
.check_run()
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2019-08-22 21:46:06 +03:00
|
|
|
run_type.execute(shell()).arg("-c").arg(command).check_run()
|
2018-08-19 14:45:23 +03:00
|
|
|
}
|
2018-10-02 13:45:29 +03:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
pub fn run_composer_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let composer = utils::require("composer")?;
|
|
|
|
|
let composer_home = Command::new(&composer)
|
2019-07-01 08:56:18 +03:00
|
|
|
.args(&["global", "config", "--absolute", "--quiet", "home"])
|
2019-01-13 23:20:32 +02:00
|
|
|
.check_output()
|
|
|
|
|
.map_err(|_| Error::from(ErrorKind::SkipStep))
|
2019-07-01 08:56:18 +03:00
|
|
|
.map(|s| PathBuf::from(s.trim()))
|
2019-04-14 11:35:18 +03:00
|
|
|
.and_then(PathExt::require)?;
|
2019-01-13 23:20:32 +02:00
|
|
|
|
|
|
|
|
if !composer_home.is_descendant_of(base_dirs.home_dir()) {
|
|
|
|
|
Err(ErrorKind::SkipStep)?;
|
|
|
|
|
}
|
2018-12-17 10:53:05 +02:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
print_separator("Composer");
|
2018-12-17 10:53:05 +02:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
run_type.execute(&composer).args(&["global", "update"]).check_run()?;
|
2018-10-02 13:45:29 +03:00
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
if let Some(valet) = utils::which("valet") {
|
|
|
|
|
run_type.execute(&valet).arg("install").check_run()?;
|
2018-10-02 13:45:29 +03:00
|
|
|
}
|
|
|
|
|
|
2019-01-13 23:20:32 +02:00
|
|
|
Ok(())
|
2018-10-02 13:45:29 +03:00
|
|
|
}
|
2019-06-05 14:15:45 +03:00
|
|
|
|
2019-06-13 16:43:23 +03:00
|
|
|
pub fn run_remote_topgrade(run_type: RunType, hostname: &str, run_in_tmux: bool) -> Result<(), Error> {
|
2019-06-05 14:15:45 +03:00
|
|
|
let ssh = utils::require("ssh")?;
|
|
|
|
|
|
2019-06-13 16:43:23 +03:00
|
|
|
if run_in_tmux && !run_type.dry() {
|
|
|
|
|
#[cfg(unix)]
|
|
|
|
|
{
|
|
|
|
|
crate::tmux::run_remote_topgrade(hostname, &ssh)?;
|
|
|
|
|
Err(ErrorKind::SkipStep)?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unreachable!("Tmux execution is only implemented in Unix");
|
|
|
|
|
} else {
|
|
|
|
|
run_type
|
|
|
|
|
.execute(&ssh)
|
|
|
|
|
.args(&[
|
|
|
|
|
"-t",
|
|
|
|
|
hostname,
|
|
|
|
|
"env",
|
|
|
|
|
&format!("TOPGRADE_PREFIX={}", hostname),
|
|
|
|
|
"topgrade",
|
|
|
|
|
])
|
|
|
|
|
.check_run()
|
|
|
|
|
}
|
2019-06-05 14:15:45 +03:00
|
|
|
}
|