Add check_run()

This commit is contained in:
Roey Darwish Dror
2018-12-31 22:00:34 +02:00
parent a404df9c97
commit f3f8f322d8
11 changed files with 71 additions and 215 deletions

View File

@@ -124,6 +124,13 @@ impl Executor {
Ok(result) Ok(result)
} }
/// A convinence method for `spawn().wait().check()`.
/// Returns an error if something went wrong during the execution or if the
/// process exited with failure.
pub fn check_run(&mut self) -> Result<(), Error> {
self.spawn()?.wait()?.check()
}
} }
/// A struct represending a command. Trying to execute it will just print its arguments. /// A struct represending a command. Trying to execute it will just print its arguments.

View File

@@ -18,9 +18,7 @@ pub fn run_cargo_update(run_type: RunType) -> Option<(&'static str, bool)> {
run_type run_type
.execute(cargo_update) .execute(cargo_update)
.args(&["install-update", "--git", "--all"]) .args(&["install-update", "--git", "--all"])
.spawn()? .check_run()?;
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
@@ -39,12 +37,7 @@ pub fn run_gem(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str,
print_separator("RubyGems"); print_separator("RubyGems");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type run_type.execute(&gem).args(&["update", "--user-install"]).check_run()?;
.execute(&gem)
.args(&["update", "--user-install"])
.spawn()?
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
@@ -66,9 +59,7 @@ pub fn run_emacs(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static st
run_type run_type
.execute(&emacs) .execute(&emacs)
.args(&["--batch", "-l", init_file.to_str().unwrap(), "--eval", EMACS_UPGRADE]) .args(&["--batch", "-l", init_file.to_str().unwrap(), "--eval", EMACS_UPGRADE])
.spawn()? .check_run()?;
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
@@ -95,9 +86,7 @@ pub fn run_apm(run_type: RunType) -> Option<(&'static str, bool)> {
run_type run_type
.execute(&apm) .execute(&apm)
.args(&["upgrade", "--confirm=false"]) .args(&["upgrade", "--confirm=false"])
.spawn()? .check_run()?;
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
@@ -116,15 +105,10 @@ pub fn run_rustup(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static s
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
if rustup.is_descendant_of(base_dirs.home_dir()) { if rustup.is_descendant_of(base_dirs.home_dir()) {
run_type run_type.execute(&rustup).args(&["self", "update"]).check_run()?;
.execute(&rustup)
.args(&["self", "update"])
.spawn()?
.wait()?
.check()?;
} }
run_type.execute(&rustup).arg("update").spawn()?.wait()?; run_type.execute(&rustup).arg("update").check_run()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -141,12 +125,7 @@ pub fn run_jetpack(run_type: RunType) -> Option<(&'static str, bool)> {
print_separator("Jetpack"); print_separator("Jetpack");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type run_type.execute(&jetpack).args(&["global", "update"]).check_run()?;
.execute(&jetpack)
.args(&["global", "update"])
.spawn()?
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -163,8 +142,8 @@ pub fn run_opam_update(run_type: RunType) -> Option<(&'static str, bool)> {
print_separator("OCaml Package Manager"); print_separator("OCaml Package Manager");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type.execute(&opam).arg("update").spawn()?.wait()?; run_type.execute(&opam).arg("update").check_run()?;
run_type.execute(&opam).arg("upgrade").spawn()?.wait()?; run_type.execute(&opam).arg("upgrade").check_run()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -184,9 +163,7 @@ pub fn run_vcpkg_update(run_type: RunType) -> Option<(&'static str, bool)> {
run_type run_type
.execute(&vcpkg) .execute(&vcpkg)
.args(&["upgrade", "--no-dry-run"]) .args(&["upgrade", "--no-dry-run"])
.spawn()? .check_run()?;
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -203,7 +180,7 @@ pub fn run_pipx_update(run_type: RunType) -> Option<(&'static str, bool)> {
print_separator("pipx"); print_separator("pipx");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type.execute(&pipx).arg("upgrade-all").spawn()?.wait()?.check()?; run_type.execute(&pipx).arg("upgrade-all").check_run()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -217,7 +194,7 @@ pub fn run_pipx_update(run_type: RunType) -> Option<(&'static str, bool)> {
#[must_use] #[must_use]
pub fn run_custom_command(name: &str, command: &str, run_type: RunType) -> Result<(), Error> { pub fn run_custom_command(name: &str, command: &str, run_type: RunType) -> Result<(), Error> {
print_separator(name); print_separator(name);
run_type.execute("sh").arg("-c").arg(command).spawn()?.wait()?.check()?; run_type.execute("sh").arg("-c").arg(command).check_run()?;
Ok(()) Ok(())
} }
@@ -241,15 +218,10 @@ pub fn run_composer_update(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&
print_separator("Composer"); print_separator("Composer");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type run_type.execute(&composer).args(&["global", "update"]).check_run()?;
.execute(&composer)
.args(&["global", "update"])
.spawn()?
.wait()?
.check()?;
if let Some(valet) = utils::which("valet") { if let Some(valet) = utils::which("valet") {
run_type.execute(&valet).arg("install").spawn()?.wait()?; run_type.execute(&valet).arg("install").check_run()?;
} }
Ok(()) Ok(())

View File

@@ -1,7 +1,7 @@
use crate::error::Error; use crate::error::Error;
use crate::executor::RunType; use crate::executor::RunType;
use crate::terminal::print_separator; use crate::terminal::print_separator;
use crate::utils::{which, Check}; use crate::utils::which;
use log::{debug, error}; use log::{debug, error};
use std::collections::HashSet; use std::collections::HashSet;
use std::io; use std::io;
@@ -70,17 +70,13 @@ impl Git {
.execute(git) .execute(git)
.args(&["pull", "--rebase", "--autostash"]) .args(&["pull", "--rebase", "--autostash"])
.current_dir(&path) .current_dir(&path)
.spawn()? .check_run()?;
.wait()?
.check()?;
run_type run_type
.execute(git) .execute(git)
.args(&["submodule", "update", "--init", "--recursive"]) .args(&["submodule", "update", "--init", "--recursive"])
.current_dir(&path) .current_dir(&path)
.spawn()? .check_run()?;
.wait()?
.check()?;
Ok(()) Ok(())
}() }()

View File

@@ -30,12 +30,7 @@ impl NPM {
} }
fn upgrade(&self, run_type: RunType) -> Result<(), Error> { fn upgrade(&self, run_type: RunType) -> Result<(), Error> {
run_type run_type.execute(&self.command).args(&["update", "-g"]).check_run()?;
.execute(&self.command)
.args(&["update", "-g"])
.spawn()?
.wait()?
.check()?;
Ok(()) Ok(())
} }
@@ -61,12 +56,7 @@ pub fn yarn_global_update(run_type: RunType) -> Option<(&'static str, bool)> {
print_separator("Yarn"); print_separator("Yarn");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type run_type.execute(&yarn).args(&["global", "upgrade", "-s"]).check_run()?;
.execute(&yarn)
.args(&["global", "upgrade", "-s"])
.spawn()?
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();

View File

@@ -15,9 +15,7 @@ pub fn upgrade_freebsd(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'s
run_type run_type
.execute(sudo) .execute(sudo)
.args(&["/usr/sbin/freebsd-update", "fetch", "install"]) .args(&["/usr/sbin/freebsd-update", "fetch", "install"])
.spawn()? .check_run()?;
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -35,12 +33,7 @@ pub fn upgrade_packages(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'
if let Some(sudo) = sudo { if let Some(sudo) = sudo {
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type run_type.execute(sudo).args(&["/usr/sbin/pkg", "upgrade"]).check_run()?;
.execute(sudo)
.args(&["/usr/sbin/pkg", "upgrade"])
.spawn()?
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();

View File

@@ -1,7 +1,7 @@
use crate::error::{Error, ErrorKind}; use crate::error::{Error, ErrorKind};
use crate::executor::RunType; use crate::executor::RunType;
use crate::terminal::{print_separator, print_warning}; use crate::terminal::{print_separator, print_warning};
use crate::utils::{which, Check}; use crate::utils::which;
use failure::ResultExt; use failure::ResultExt;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
@@ -115,26 +115,16 @@ It's dangerous to run yay since Python based AUR packages will be installed in t
return Err(ErrorKind::NotSystemPython)?; return Err(ErrorKind::NotSystemPython)?;
} }
} }
run_type.execute(yay).spawn()?.wait()?.check()?; run_type.execute(yay).check_run()?;
} else if let Some(sudo) = &sudo { } else if let Some(sudo) = &sudo {
run_type run_type.execute(&sudo).args(&["/usr/bin/pacman", "-Syu"]).check_run()?;
.execute(&sudo)
.args(&["/usr/bin/pacman", "-Syu"])
.spawn()?
.wait()?
.check()?;
} else { } else {
print_warning("No sudo or yay detected. Skipping system upgrade"); print_warning("No sudo or yay detected. Skipping system upgrade");
} }
if cleanup { if cleanup {
if let Some(sudo) = &sudo { if let Some(sudo) = &sudo {
run_type run_type.execute(&sudo).args(&["/usr/bin/pacman", "-Scc"]).check_run()?;
.execute(&sudo)
.args(&["/usr/bin/pacman", "-Scc"])
.spawn()?
.wait()?
.check()?;
} }
} }
@@ -143,12 +133,7 @@ It's dangerous to run yay since Python based AUR packages will be installed in t
fn upgrade_redhat(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> { fn upgrade_redhat(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
if let Some(sudo) = &sudo { if let Some(sudo) = &sudo {
run_type run_type.execute(&sudo).args(&["/usr/bin/yum", "upgrade"]).check_run()?;
.execute(&sudo)
.args(&["/usr/bin/yum", "upgrade"])
.spawn()?
.wait()?
.check()?;
} else { } else {
print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
} }
@@ -161,16 +146,12 @@ fn upgrade_opensuse(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Err
run_type run_type
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/zypper", "refresh"]) .args(&["/usr/bin/zypper", "refresh"])
.spawn()? .check_run()?;
.wait()?
.check()?;
run_type run_type
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/zypper", "dist-upgrade"]) .args(&["/usr/bin/zypper", "dist-upgrade"])
.spawn()? .check_run()?;
.wait()?
.check()?;
} else { } else {
print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
} }
@@ -183,9 +164,7 @@ fn upgrade_void(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error>
run_type run_type
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/xbps-install", "-Su"]) .args(&["/usr/bin/xbps-install", "-Su"])
.spawn()? .check_run()?;
.wait()?
.check()?;
} else { } else {
print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
} }
@@ -195,12 +174,7 @@ fn upgrade_void(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error>
fn upgrade_fedora(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> { fn upgrade_fedora(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
if let Some(sudo) = &sudo { if let Some(sudo) = &sudo {
run_type run_type.execute(&sudo).args(&["/usr/bin/dnf", "upgrade"]).check_run()?;
.execute(&sudo)
.args(&["/usr/bin/dnf", "upgrade"])
.spawn()?
.wait()?
.check()?;
} else { } else {
print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
} }
@@ -211,13 +185,7 @@ fn upgrade_fedora(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error
fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> { fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
if let Some(sudo) = &sudo { if let Some(sudo) = &sudo {
if let Some(layman) = which("layman") { if let Some(layman) = which("layman") {
run_type run_type.execute(&sudo).arg(layman).args(&["-s", "ALL"]).check_run()?;
.execute(&sudo)
.arg(layman)
.args(&["-s", "ALL"])
.spawn()?
.wait()?
.check()?;
} }
println!("Syncing portage"); println!("Syncing portage");
@@ -225,21 +193,17 @@ fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error
.execute(&sudo) .execute(&sudo)
.arg("/usr/bin/emerge") .arg("/usr/bin/emerge")
.args(&["-q", "--sync"]) .args(&["-q", "--sync"])
.spawn()? .check_run()?;
.wait()?
.check()?;
if let Some(eix_update) = which("eix-update") { if let Some(eix_update) = which("eix-update") {
run_type.execute(&sudo).arg(eix_update).spawn()?.wait()?; run_type.execute(&sudo).arg(eix_update).check_run()?;
} }
run_type run_type
.execute(&sudo) .execute(&sudo)
.arg("/usr/bin/emerge") .arg("/usr/bin/emerge")
.args(&["-uDNa", "world"]) .args(&["-uDNa", "world"])
.spawn()? .check_run()?;
.wait()?
.check()?;
} else { } else {
print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
} }
@@ -249,34 +213,20 @@ fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error
fn upgrade_debian(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Result<(), Error> { fn upgrade_debian(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Result<(), Error> {
if let Some(sudo) = &sudo { if let Some(sudo) = &sudo {
run_type run_type.execute(&sudo).args(&["/usr/bin/apt", "update"]).check_run()?;
.execute(&sudo)
.args(&["/usr/bin/apt", "update"])
.spawn()?
.wait()?
.check()?;
run_type run_type
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/apt", "dist-upgrade"]) .args(&["/usr/bin/apt", "dist-upgrade"])
.spawn()? .check_run()?;
.wait()?
.check()?;
if cleanup { if cleanup {
run_type run_type.execute(&sudo).args(&["/usr/bin/apt", "clean"]).check_run()?;
.execute(&sudo)
.args(&["/usr/bin/apt", "clean"])
.spawn()?
.wait()?
.check()?;
run_type run_type
.execute(&sudo) .execute(&sudo)
.args(&["/usr/bin/apt", "autoremove"]) .args(&["/usr/bin/apt", "autoremove"])
.spawn()? .check_run()?;
.wait()?
.check()?;
} }
} else { } else {
print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
@@ -292,7 +242,7 @@ pub fn run_needrestart(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'s
print_separator("Check for needed restarts"); print_separator("Check for needed restarts");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type.execute(&sudo).arg(needrestart).spawn()?.wait()?.check()?; run_type.execute(&sudo).arg(needrestart).check_run()?;
Ok(()) Ok(())
}() }()
@@ -311,13 +261,8 @@ pub fn run_fwupdmgr(run_type: RunType) -> Option<(&'static str, bool)> {
print_separator("Firmware upgrades"); print_separator("Firmware upgrades");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type.execute(&fwupdmgr).arg("refresh").spawn()?.wait()?.check()?; run_type.execute(&fwupdmgr).arg("refresh").check_run()?;
run_type run_type.execute(&fwupdmgr).arg("get-updates").check_run()?;
.execute(&fwupdmgr)
.arg("get-updates")
.spawn()?
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -337,9 +282,7 @@ pub fn flatpak_user_update(run_type: RunType) -> Option<(&'static str, bool)> {
run_type run_type
.execute(&flatpak) .execute(&flatpak)
.args(&["update", "--user", "-y"]) .args(&["update", "--user", "-y"])
.spawn()? .check_run()?;
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -360,9 +303,7 @@ pub fn flatpak_global_update(sudo: &Option<PathBuf>, run_type: RunType) -> Optio
run_type run_type
.execute(&sudo) .execute(&sudo)
.args(&[flatpak.to_str().unwrap(), "update", "-y"]) .args(&[flatpak.to_str().unwrap(), "update", "-y"])
.spawn()? .check_run()?;
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -385,9 +326,7 @@ pub fn run_snap(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'static s
run_type run_type
.execute(&sudo) .execute(&sudo)
.args(&[snap.to_str().unwrap(), "refresh"]) .args(&[snap.to_str().unwrap(), "refresh"])
.spawn()? .check_run()?;
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
@@ -408,12 +347,7 @@ pub fn run_etc_update(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'st
print_separator("etc-update"); print_separator("etc-update");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type run_type.execute(&sudo).arg(&etc_update.to_str().unwrap()).check_run()?;
.execute(&sudo)
.arg(&etc_update.to_str().unwrap())
.spawn()?
.wait()?
.check()?;
Ok(()) Ok(())
}() }()

View File

@@ -1,7 +1,6 @@
use crate::error::Error; use crate::error::Error;
use crate::executor::RunType; use crate::executor::RunType;
use crate::terminal::print_separator; use crate::terminal::print_separator;
use crate::utils::Check;
#[must_use] #[must_use]
pub fn upgrade_macos(run_type: RunType) -> Option<(&'static str, bool)> { pub fn upgrade_macos(run_type: RunType) -> Option<(&'static str, bool)> {
@@ -11,9 +10,7 @@ pub fn upgrade_macos(run_type: RunType) -> Option<(&'static str, bool)> {
run_type run_type
.execute("softwareupdate") .execute("softwareupdate")
.args(&["--install", "--all"]) .args(&["--install", "--all"])
.spawn()? .check_run()?;
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();

View File

@@ -1,7 +1,7 @@
use crate::error::Error; use crate::error::Error;
use crate::executor::RunType; use crate::executor::RunType;
use crate::terminal::print_separator; use crate::terminal::print_separator;
use crate::utils::{which, Check}; use crate::utils::which;
use directories::BaseDirs; use directories::BaseDirs;
pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> { pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> {
@@ -13,9 +13,7 @@ pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static st
run_type run_type
.execute(zsh) .execute(zsh)
.args(&["-c", "source ~/.zshrc && zplug update"]) .args(&["-c", "source ~/.zshrc && zplug update"])
.spawn()? .check_run()?;
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -36,15 +34,8 @@ pub fn run_fisher(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static s
run_type run_type
.execute(&fish) .execute(&fish)
.args(&["-c", "fisher self-update"]) .args(&["-c", "fisher self-update"])
.spawn()? .check_run()?;
.wait()? run_type.execute(&fish).args(&["-c", "fisher"]).check_run()?;
.check()?;
run_type
.execute(&fish)
.args(&["-c", "fisher"])
.spawn()?
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -62,16 +53,11 @@ pub fn run_homebrew(cleanup: bool, run_type: RunType) -> Option<(&'static str, b
print_separator("Brew"); print_separator("Brew");
let inner = || -> Result<(), Error> { let inner = || -> Result<(), Error> {
run_type.execute(&brew).arg("update").spawn()?.wait()?; run_type.execute(&brew).arg("update").check_run()?;
run_type.execute(&brew).arg("upgrade").spawn()?.wait()?; run_type.execute(&brew).arg("upgrade").check_run()?;
run_type run_type.execute(&brew).args(&["cask", "upgrade"]).check_run()?;
.execute(&brew)
.args(&["cask", "upgrade"])
.spawn()?
.wait()?
.check()?;
if cleanup { if cleanup {
run_type.execute(&brew).arg("cleanup").spawn()?.wait()?; run_type.execute(&brew).arg("cleanup").check_run()?;
} }
Ok(()) Ok(())
}; };
@@ -89,8 +75,8 @@ pub fn run_nix(run_type: RunType) -> Option<(&'static str, bool)> {
print_separator("Nix"); print_separator("Nix");
let inner = || -> Result<(), Error> { let inner = || -> Result<(), Error> {
run_type.execute(&nix).arg("upgrade-nix").spawn()?.wait()?.check()?; run_type.execute(&nix).arg("upgrade-nix").check_run()?;
run_type.execute(&nix_env).arg("--upgrade").spawn()?.wait()?.check()?; run_type.execute(&nix_env).arg("--upgrade").check_run()?;
Ok(()) Ok(())
}; };

View File

@@ -13,12 +13,7 @@ pub fn run_chocolatey(run_type: RunType) -> Option<(&'static str, bool)> {
print_separator("Chocolatey"); print_separator("Chocolatey");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type run_type.execute(&choco).args(&["upgrade", "all"]).check_run()?;
.execute(&choco)
.args(&["upgrade", "all"])
.spawn()?
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -35,13 +30,8 @@ pub fn run_scoop(run_type: RunType) -> Option<(&'static str, bool)> {
print_separator("Scoop"); print_separator("Scoop");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type.execute(&scoop).args(&["update"]).spawn()?.wait()?.check()?; run_type.execute(&scoop).args(&["update"]).check_run()?;
run_type run_type.execute(&scoop).args(&["update", "*"]).check_run()?;
.execute(&scoop)
.args(&["update", "*"])
.spawn()?
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -102,12 +92,7 @@ impl Powershell {
print_separator("Powershell Modules Update"); print_separator("Powershell Modules Update");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type run_type.execute(&powershell).arg("Update-Module").check_run()?;
.execute(&powershell)
.arg("Update-Module")
.spawn()?
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();
@@ -128,9 +113,7 @@ impl Powershell {
run_type run_type
.execute(&powershell) .execute(&powershell)
.args(&["-Command", "Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -Verbose"]) .args(&["-Command", "Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -Verbose"])
.spawn()? .check_run()?;
.wait()?
.check()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();

View File

@@ -19,7 +19,7 @@ pub fn run_tpm(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str,
print_separator("tmux plugins"); print_separator("tmux plugins");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
run_type.execute(&tpm).arg("all").spawn()?.wait()?; run_type.execute(&tpm).arg("all").check_run()?;
Ok(()) Ok(())
}() }()
.is_ok(); .is_ok();

View File

@@ -1,7 +1,7 @@
use crate::error::Error; use crate::error::Error;
use crate::executor::RunType; use crate::executor::RunType;
use crate::terminal::print_separator; use crate::terminal::print_separator;
use crate::utils::{which, Check, PathExt}; use crate::utils::{which, PathExt};
use directories::BaseDirs; use directories::BaseDirs;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
@@ -69,9 +69,7 @@ fn upgrade(vim: &PathBuf, vimrc: &PathBuf, plugin_framework: PluginFramework, ru
"-s", "-s",
"-V1", "-V1",
]) ])
.spawn()? .check_run()?;
.wait()?
.check()?;
println!(); println!();