Stop passing the terminal object

This commit is contained in:
Roey Darwish Dror
2018-12-05 11:34:08 +02:00
parent 09cfb81ba5
commit 39faab0a12
14 changed files with 217 additions and 323 deletions

View File

@@ -22,10 +22,10 @@ env_logger = "0.5.13"
walkdir = "2.2.6" walkdir = "2.2.6"
console = "0.6.2" console = "0.6.2"
self_update = { version = "0.5.0", optional = true } self_update = { version = "0.5.0", optional = true }
lazy_static = "1.1.0"
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
nix = "0.11.0" nix = "0.11.0"
lazy_static = "1.1.0"
[profile.release] [profile.release]
lto = true lto = true

View File

@@ -1,13 +1,13 @@
use super::executor::Executor; use super::executor::Executor;
use super::terminal::Terminal; use super::terminal::{print_separator, print_warning};
use super::utils::Check; use super::utils::Check;
use failure; use failure;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
#[must_use] #[must_use]
pub fn upgrade_freebsd(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn upgrade_freebsd(sudo: &Option<PathBuf>, dry_run: bool) -> Option<(&'static str, bool)> {
terminal.print_separator("FreeBSD Update"); print_separator("FreeBSD Update");
if let Some(sudo) = sudo { if let Some(sudo) = sudo {
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
@@ -21,18 +21,14 @@ pub fn upgrade_freebsd(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run:
Some(("FreeBSD Update", success)) Some(("FreeBSD Update", success))
} else { } else {
terminal.print_warning("No sudo or yay detected. Skipping system upgrade"); print_warning("No sudo or yay detected. Skipping system upgrade");
None None
} }
} }
#[must_use] #[must_use]
pub fn upgrade_packages( pub fn upgrade_packages(sudo: &Option<PathBuf>, dry_run: bool) -> Option<(&'static str, bool)> {
sudo: &Option<PathBuf>, print_separator("FreeBSD Packages");
terminal: &mut Terminal,
dry_run: bool,
) -> Option<(&'static str, bool)> {
terminal.print_separator("FreeBSD Packages");
if let Some(sudo) = sudo { if let Some(sudo) = sudo {
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
@@ -46,7 +42,7 @@ pub fn upgrade_packages(
Some(("FreeBSD Packages", success)) Some(("FreeBSD Packages", success))
} else { } else {
terminal.print_warning("No sudo or yay detected. Skipping package upgrade"); print_warning("No sudo or yay detected. Skipping package upgrade");
None None
} }
} }

View File

@@ -1,5 +1,5 @@
use super::executor::Executor; use super::executor::Executor;
use super::terminal::Terminal; use super::terminal::print_separator;
use super::utils::{self, Check, PathExt}; use super::utils::{self, Check, PathExt};
use directories::BaseDirs; use directories::BaseDirs;
use failure::Error; use failure::Error;
@@ -9,9 +9,9 @@ use std::process::Command;
const EMACS_UPGRADE: &str = include_str!("emacs.el"); const EMACS_UPGRADE: &str = include_str!("emacs.el");
#[must_use] #[must_use]
pub fn run_cargo_update(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_cargo_update(dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(cargo_update) = utils::which("cargo-install-update") { if let Some(cargo_update) = utils::which("cargo-install-update") {
terminal.print_separator("Cargo"); print_separator("Cargo");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
Executor::new(cargo_update, dry_run) Executor::new(cargo_update, dry_run)
@@ -30,10 +30,10 @@ pub fn run_cargo_update(terminal: &mut Terminal, dry_run: bool) -> Option<(&'sta
} }
#[must_use] #[must_use]
pub fn run_gem(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_gem(base_dirs: &BaseDirs, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(gem) = utils::which("gem") { if let Some(gem) = utils::which("gem") {
if base_dirs.home_dir().join(".gem").exists() { if base_dirs.home_dir().join(".gem").exists() {
terminal.print_separator("RubyGems"); print_separator("RubyGems");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
Executor::new(&gem, dry_run) Executor::new(&gem, dry_run)
@@ -52,10 +52,10 @@ pub fn run_gem(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) ->
} }
#[must_use] #[must_use]
pub fn run_emacs(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_emacs(base_dirs: &BaseDirs, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(emacs) = utils::which("emacs") { if let Some(emacs) = utils::which("emacs") {
if let Some(init_file) = base_dirs.home_dir().join(".emacs.d/init.el").if_exists() { if let Some(init_file) = base_dirs.home_dir().join(".emacs.d/init.el").if_exists() {
terminal.print_separator("Emacs"); print_separator("Emacs");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
Executor::new(&emacs, dry_run) Executor::new(&emacs, dry_run)
@@ -80,9 +80,9 @@ pub fn run_emacs(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -
target_os = "netbsd", target_os = "netbsd",
target_os = "dragonfly" target_os = "dragonfly"
)))] )))]
pub fn run_apm(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_apm(dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(apm) = utils::which("apm") { if let Some(apm) = utils::which("apm") {
terminal.print_separator("Atom Package Manager"); print_separator("Atom Package Manager");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
Executor::new(&apm, dry_run) Executor::new(&apm, dry_run)
@@ -101,9 +101,9 @@ pub fn run_apm(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str,
} }
#[must_use] #[must_use]
pub fn run_rustup(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_rustup(base_dirs: &BaseDirs, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(rustup) = utils::which("rustup") { if let Some(rustup) = utils::which("rustup") {
terminal.print_separator("rustup"); print_separator("rustup");
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()) {
@@ -125,9 +125,9 @@ pub fn run_rustup(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool)
} }
#[must_use] #[must_use]
pub fn run_jetpack(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_jetpack(dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(jetpack) = utils::which("jetpack") { if let Some(jetpack) = utils::which("jetpack") {
terminal.print_separator("Jetpack"); print_separator("Jetpack");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
Executor::new(&jetpack, dry_run) Executor::new(&jetpack, dry_run)
@@ -145,9 +145,9 @@ pub fn run_jetpack(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static s
} }
#[must_use] #[must_use]
pub fn run_opam_update(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_opam_update(dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(opam) = utils::which("opam") { if let Some(opam) = utils::which("opam") {
terminal.print_separator("OCaml Package Manager"); print_separator("OCaml Package Manager");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
Executor::new(&opam, dry_run).arg("update").spawn()?.wait()?.check()?; Executor::new(&opam, dry_run).arg("update").spawn()?.wait()?.check()?;
@@ -162,12 +162,16 @@ pub fn run_opam_update(terminal: &mut Terminal, dry_run: bool) -> Option<(&'stat
} }
#[must_use] #[must_use]
pub fn run_vcpkg_update(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_vcpkg_update(dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(vcpkg) = utils::which("vcpkg") { if let Some(vcpkg) = utils::which("vcpkg") {
terminal.print_separator("vcpkg"); print_separator("vcpkg");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
Executor::new(&vcpkg, dry_run).args(&["upgrade", "--no-dry-run"]).spawn()?.wait()?.check()?; Executor::new(&vcpkg, dry_run)
.args(&["upgrade", "--no-dry-run"])
.spawn()?
.wait()?
.check()?;
Ok(()) Ok(())
}().is_ok(); }().is_ok();
@@ -178,9 +182,9 @@ pub fn run_vcpkg_update(terminal: &mut Terminal, dry_run: bool) -> Option<(&'sta
} }
#[must_use] #[must_use]
pub fn run_pipx_update(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_pipx_update(dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(pipx) = utils::which("pipx") { if let Some(pipx) = utils::which("pipx") {
terminal.print_separator("pipx"); print_separator("pipx");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
Executor::new(&pipx, dry_run) Executor::new(&pipx, dry_run)
@@ -198,8 +202,8 @@ pub fn run_pipx_update(terminal: &mut Terminal, dry_run: bool) -> Option<(&'stat
} }
#[must_use] #[must_use]
pub fn run_custom_command(name: &str, command: &str, terminal: &mut Terminal, dry_run: bool) -> Result<(), Error> { pub fn run_custom_command(name: &str, command: &str, dry_run: bool) -> Result<(), Error> {
terminal.print_separator(name); print_separator(name);
Executor::new("sh", dry_run) Executor::new("sh", dry_run)
.arg("-c") .arg("-c")
.arg(command) .arg(command)
@@ -211,11 +215,7 @@ pub fn run_custom_command(name: &str, command: &str, terminal: &mut Terminal, dr
} }
#[must_use] #[must_use]
pub fn run_composer_update( pub fn run_composer_update(base_dirs: &BaseDirs, dry_run: bool) -> Option<(&'static str, bool)> {
base_dirs: &BaseDirs,
terminal: &mut Terminal,
dry_run: bool,
) -> Option<(&'static str, bool)> {
if let Some(composer) = utils::which("composer") { if let Some(composer) = utils::which("composer") {
let composer_home = || -> Result<PathBuf, Error> { let composer_home = || -> Result<PathBuf, Error> {
let output = Command::new(&composer) let output = Command::new(&composer)
@@ -227,7 +227,7 @@ pub fn run_composer_update(
if let Ok(composer_home) = composer_home { if let Ok(composer_home) = composer_home {
if composer_home.is_descendant_of(base_dirs.home_dir()) { if composer_home.is_descendant_of(base_dirs.home_dir()) {
terminal.print_separator("Composer"); print_separator("Composer");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
Executor::new(&composer, dry_run) Executor::new(&composer, dry_run)

View File

@@ -1,5 +1,5 @@
use super::executor::Executor; use super::executor::Executor;
use super::terminal::Terminal; use super::terminal::print_separator;
use super::utils::{which, Check}; use super::utils::{which, Check};
use failure::Error; use failure::Error;
use log::{debug, error}; use log::{debug, error};
@@ -58,10 +58,10 @@ impl Git {
None None
} }
pub fn pull<P: AsRef<Path>>(&self, path: P, terminal: &mut Terminal, dry_run: bool) -> Option<(String, bool)> { pub fn pull<P: AsRef<Path>>(&self, path: P, dry_run: bool) -> Option<(String, bool)> {
let path = path.as_ref(); let path = path.as_ref();
terminal.print_separator(format!("Pulling {}", path.display())); print_separator(format!("Pulling {}", path.display()));
let git = self.git.as_ref().unwrap(); let git = self.git.as_ref().unwrap();

View File

@@ -1,5 +1,5 @@
use super::executor::Executor; use super::executor::Executor;
use super::terminal::Terminal; use super::terminal::{print_separator, print_warning};
use super::utils::{which, Check}; use super::utils::{which, Check};
use failure; use failure;
use failure_derive::Fail; use failure_derive::Fail;
@@ -67,22 +67,17 @@ impl Distribution {
} }
#[must_use] #[must_use]
pub fn upgrade( pub fn upgrade(self, sudo: &Option<PathBuf>, dry_run: bool) -> Option<(&'static str, bool)> {
self, print_separator("System update");
sudo: &Option<PathBuf>,
terminal: &mut Terminal,
dry_run: bool,
) -> Option<(&'static str, bool)> {
terminal.print_separator("System update");
let success = match self { let success = match self {
Distribution::Arch => upgrade_arch_linux(&sudo, terminal, dry_run), Distribution::Arch => upgrade_arch_linux(&sudo, dry_run),
Distribution::CentOS => upgrade_redhat(&sudo, terminal, dry_run), Distribution::CentOS => upgrade_redhat(&sudo, dry_run),
Distribution::Fedora => upgrade_fedora(&sudo, terminal, dry_run), Distribution::Fedora => upgrade_fedora(&sudo, dry_run),
Distribution::Ubuntu | Distribution::Debian => upgrade_debian(&sudo, terminal, dry_run), Distribution::Ubuntu | Distribution::Debian => upgrade_debian(&sudo, dry_run),
Distribution::Gentoo => upgrade_gentoo(&sudo, terminal, dry_run), Distribution::Gentoo => upgrade_gentoo(&sudo, dry_run),
Distribution::OpenSuse => upgrade_opensuse(&sudo, terminal, dry_run), Distribution::OpenSuse => upgrade_opensuse(&sudo, dry_run),
Distribution::Void => upgrade_void(&sudo, terminal, dry_run), Distribution::Void => upgrade_void(&sudo, dry_run),
}; };
Some(("System update", success.is_ok())) Some(("System update", success.is_ok()))
@@ -115,11 +110,11 @@ pub fn show_pacnew() {
} }
} }
fn upgrade_arch_linux(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> { fn upgrade_arch_linux(sudo: &Option<PathBuf>, dry_run: bool) -> Result<(), failure::Error> {
if let Some(yay) = which("yay") { if let Some(yay) = which("yay") {
if let Some(python) = which("python") { if let Some(python) = which("python") {
if python != PathBuf::from("/usr/bin/python") { if python != PathBuf::from("/usr/bin/python") {
terminal.print_warning(format!( print_warning(format!(
"Python detected at {:?}, which is probably not the system Python. "Python detected at {:?}, which is probably not the system Python.
It's dangerous to run yay since Python based AUR packages will be installed in the wrong location", It's dangerous to run yay since Python based AUR packages will be installed in the wrong location",
python python
@@ -136,13 +131,13 @@ It's dangerous to run yay since Python based AUR packages will be installed in t
.wait()? .wait()?
.check()?; .check()?;
} else { } else {
terminal.print_warning("No sudo or yay detected. Skipping system upgrade"); print_warning("No sudo or yay detected. Skipping system upgrade");
} }
Ok(()) Ok(())
} }
fn upgrade_redhat(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> { fn upgrade_redhat(sudo: &Option<PathBuf>, dry_run: bool) -> Result<(), failure::Error> {
if let Some(sudo) = &sudo { if let Some(sudo) = &sudo {
Executor::new(&sudo, dry_run) Executor::new(&sudo, dry_run)
.args(&["/usr/bin/yum", "upgrade"]) .args(&["/usr/bin/yum", "upgrade"])
@@ -150,13 +145,13 @@ fn upgrade_redhat(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool
.wait()? .wait()?
.check()?; .check()?;
} else { } else {
terminal.print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
} }
Ok(()) Ok(())
} }
fn upgrade_opensuse(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> { fn upgrade_opensuse(sudo: &Option<PathBuf>, dry_run: bool) -> Result<(), failure::Error> {
if let Some(sudo) = &sudo { if let Some(sudo) = &sudo {
Executor::new(&sudo, dry_run) Executor::new(&sudo, dry_run)
.args(&["/usr/bin/zypper", "refresh"]) .args(&["/usr/bin/zypper", "refresh"])
@@ -170,13 +165,13 @@ fn upgrade_opensuse(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bo
.wait()? .wait()?
.check()?; .check()?;
} else { } else {
terminal.print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
} }
Ok(()) Ok(())
} }
fn upgrade_void(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> { fn upgrade_void(sudo: &Option<PathBuf>, dry_run: bool) -> Result<(), failure::Error> {
if let Some(sudo) = &sudo { if let Some(sudo) = &sudo {
Executor::new(&sudo, dry_run) Executor::new(&sudo, dry_run)
.args(&["/usr/bin/xbps-install", "-Su"]) .args(&["/usr/bin/xbps-install", "-Su"])
@@ -184,13 +179,13 @@ fn upgrade_void(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool)
.wait()? .wait()?
.check()?; .check()?;
} else { } else {
terminal.print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
} }
Ok(()) Ok(())
} }
fn upgrade_fedora(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> { fn upgrade_fedora(sudo: &Option<PathBuf>, dry_run: bool) -> Result<(), failure::Error> {
if let Some(sudo) = &sudo { if let Some(sudo) = &sudo {
Executor::new(&sudo, dry_run) Executor::new(&sudo, dry_run)
.args(&["/usr/bin/dnf", "upgrade"]) .args(&["/usr/bin/dnf", "upgrade"])
@@ -198,13 +193,13 @@ fn upgrade_fedora(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool
.wait()? .wait()?
.check()?; .check()?;
} else { } else {
terminal.print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
} }
Ok(()) Ok(())
} }
fn upgrade_gentoo(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> { fn upgrade_gentoo(sudo: &Option<PathBuf>, dry_run: bool) -> Result<(), failure::Error> {
if let Some(sudo) = &sudo { if let Some(sudo) = &sudo {
if let Some(layman) = which("layman") { if let Some(layman) = which("layman") {
Executor::new(&sudo, dry_run) Executor::new(&sudo, dry_run)
@@ -234,13 +229,13 @@ fn upgrade_gentoo(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool
.wait()? .wait()?
.check()?; .check()?;
} else { } else {
terminal.print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
} }
Ok(()) Ok(())
} }
fn upgrade_debian(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> { fn upgrade_debian(sudo: &Option<PathBuf>, dry_run: bool) -> Result<(), failure::Error> {
if let Some(sudo) = &sudo { if let Some(sudo) = &sudo {
Executor::new(&sudo, dry_run) Executor::new(&sudo, dry_run)
.args(&["/usr/bin/apt", "update"]) .args(&["/usr/bin/apt", "update"])
@@ -254,17 +249,17 @@ fn upgrade_debian(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool
.wait()? .wait()?
.check()?; .check()?;
} else { } else {
terminal.print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");
} }
Ok(()) Ok(())
} }
#[must_use] #[must_use]
pub fn run_needrestart(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_needrestart(sudo: &Option<PathBuf>, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(sudo) = sudo { if let Some(sudo) = sudo {
if let Some(needrestart) = which("needrestart") { if let Some(needrestart) = which("needrestart") {
terminal.print_separator("Check for needed restarts"); print_separator("Check for needed restarts");
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
Executor::new(&sudo, dry_run) Executor::new(&sudo, dry_run)
@@ -284,9 +279,9 @@ pub fn run_needrestart(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run:
} }
#[must_use] #[must_use]
pub fn run_fwupdmgr(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_fwupdmgr(dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(fwupdmgr) = which("fwupdmgr") { if let Some(fwupdmgr) = which("fwupdmgr") {
terminal.print_separator("Firmware upgrades"); print_separator("Firmware upgrades");
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
Executor::new(&fwupdmgr, dry_run) Executor::new(&fwupdmgr, dry_run)
@@ -309,9 +304,9 @@ pub fn run_fwupdmgr(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static
} }
#[must_use] #[must_use]
pub fn flatpak_user_update(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn flatpak_user_update(dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(flatpak) = which("flatpak") { if let Some(flatpak) = which("flatpak") {
terminal.print_separator("Flatpak User Packages"); print_separator("Flatpak User Packages");
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
Executor::new(&flatpak, dry_run) Executor::new(&flatpak, dry_run)
@@ -329,14 +324,10 @@ pub fn flatpak_user_update(terminal: &mut Terminal, dry_run: bool) -> Option<(&'
} }
#[must_use] #[must_use]
pub fn flatpak_global_update( pub fn flatpak_global_update(sudo: &Option<PathBuf>, dry_run: bool) -> Option<(&'static str, bool)> {
sudo: &Option<PathBuf>,
terminal: &mut Terminal,
dry_run: bool,
) -> Option<(&'static str, bool)> {
if let Some(sudo) = sudo { if let Some(sudo) = sudo {
if let Some(flatpak) = which("flatpak") { if let Some(flatpak) = which("flatpak") {
terminal.print_separator("Flatpak Global Packages"); print_separator("Flatpak Global Packages");
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
Executor::new(&sudo, dry_run) Executor::new(&sudo, dry_run)
@@ -355,11 +346,11 @@ pub fn flatpak_global_update(
} }
#[must_use] #[must_use]
pub fn run_snap(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_snap(sudo: &Option<PathBuf>, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(sudo) = sudo { if let Some(sudo) = sudo {
if let Some(snap) = which("snap") { if let Some(snap) = which("snap") {
if PathBuf::from("/var/snapd.socket").exists() { if PathBuf::from("/var/snapd.socket").exists() {
terminal.print_separator("snap"); print_separator("snap");
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
Executor::new(&sudo, dry_run) Executor::new(&sudo, dry_run)
@@ -380,10 +371,10 @@ pub fn run_snap(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool)
} }
#[must_use] #[must_use]
pub fn run_etc_update(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_etc_update(sudo: &Option<PathBuf>, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(sudo) = sudo { if let Some(sudo) = sudo {
if let Some(etc_update) = which("etc-update") { if let Some(etc_update) = which("etc-update") {
terminal.print_separator("etc-update"); print_separator("etc-update");
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
Executor::new(&sudo, dry_run) Executor::new(&sudo, dry_run)

View File

@@ -1,11 +1,11 @@
use super::executor::Executor; use super::executor::Executor;
use super::terminal::Terminal; use super::terminal::print_separator;
use super::utils::Check; use super::utils::Check;
use failure; use failure;
#[must_use] #[must_use]
pub fn upgrade_macos(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn upgrade_macos(dry_run: bool) -> Option<(&'static str, bool)> {
terminal.print_separator("App Store"); print_separator("App Store");
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
Executor::new("softwareupdate", dry_run) Executor::new("softwareupdate", dry_run)

View File

@@ -3,7 +3,6 @@ extern crate directories;
extern crate env_logger; extern crate env_logger;
extern crate failure; extern crate failure;
extern crate failure_derive; extern crate failure_derive;
#[cfg(unix)]
extern crate lazy_static; extern crate lazy_static;
extern crate log; extern crate log;
#[cfg(unix)] #[cfg(unix)]
@@ -47,7 +46,6 @@ mod vim;
use self::config::Config; use self::config::Config;
use self::git::{Git, Repositories}; use self::git::{Git, Repositories};
use self::report::Report; use self::report::Report;
use self::terminal::Terminal;
use failure::Error; use failure::Error;
use failure_derive::Fail; use failure_derive::Fail;
use std::borrow::Cow; use std::borrow::Cow;
@@ -55,6 +53,7 @@ use std::env;
use std::io::ErrorKind; use std::io::ErrorKind;
use std::process::exit; use std::process::exit;
use structopt::StructOpt; use structopt::StructOpt;
use terminal::*;
#[derive(Fail, Debug)] #[derive(Fail, Debug)]
#[fail(display = "A step failed")] #[fail(display = "A step failed")]
@@ -68,16 +67,12 @@ struct NoBaseDirectories;
#[fail(display = "Process Interrupted")] #[fail(display = "Process Interrupted")]
pub struct Interrupted; pub struct Interrupted;
struct ExecutionContext { fn execute<'a, F, M>(func: F) -> Result<Option<(M, bool)>, Error>
terminal: Terminal,
}
fn execute<'a, F, M>(func: F, execution_context: &mut ExecutionContext) -> Result<Option<(M, bool)>, Error>
where where
M: Into<Cow<'a, str>>, M: Into<Cow<'a, str>>,
F: Fn(&mut Terminal) -> Option<(M, bool)>, F: Fn() -> Option<(M, bool)>,
{ {
while let Some((key, success)) = func(&mut execution_context.terminal) { while let Some((key, success)) = func() {
if success { if success {
return Ok(Some((key, success))); return Ok(Some((key, success)));
} }
@@ -87,7 +82,7 @@ where
ctrlc::set_running(true); ctrlc::set_running(true);
} }
let should_retry = execution_context.terminal.should_retry(running).map_err(|e| { let should_retry = should_retry(running).map_err(|e| {
if e.kind() == ErrorKind::Interrupted { if e.kind() == ErrorKind::Interrupted {
Error::from(Interrupted) Error::from(Interrupted)
} else { } else {
@@ -117,10 +112,6 @@ fn run() -> Result<(), Error> {
env_logger::init(); env_logger::init();
let mut execution_context = ExecutionContext {
terminal: Terminal::new(),
};
let base_dirs = directories::BaseDirs::new().ok_or(NoBaseDirectories)?; let base_dirs = directories::BaseDirs::new().ok_or(NoBaseDirectories)?;
let git = Git::new(); let git = Git::new();
let mut git_repos = Repositories::new(&git); let mut git_repos = Repositories::new(&git);
@@ -134,17 +125,15 @@ fn run() -> Result<(), Error> {
#[cfg(feature = "self-update")] #[cfg(feature = "self-update")]
{ {
if !opt.dry_run { if !opt.dry_run {
if let Err(e) = self_update::self_update(&mut execution_context.terminal) { if let Err(e) = self_update::self_update() {
execution_context print_warning(format!("Self update error: {}", e));
.terminal
.print_warning(format!("Self update error: {}", e));
} }
} }
} }
if let Some(commands) = config.pre_commands() { if let Some(commands) = config.pre_commands() {
for (name, command) in commands { for (name, command) in commands {
generic::run_custom_command(&name, &command, &mut execution_context.terminal, opt.dry_run)?; generic::run_custom_command(&name, &command, opt.dry_run)?;
} }
} }
@@ -152,10 +141,7 @@ fn run() -> Result<(), Error> {
let powershell = windows::Powershell::new(); let powershell = windows::Powershell::new();
#[cfg(windows)] #[cfg(windows)]
report.push_result(execute( report.push_result(execute(|| powershell.update_modules(opt.dry_run))?);
|terminal| powershell.update_modules(terminal, opt.dry_run),
&mut execution_context,
)?);
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
let distribution = linux::Distribution::detect(); let distribution = linux::Distribution::detect();
@@ -165,49 +151,28 @@ fn run() -> Result<(), Error> {
if !opt.no_system { if !opt.no_system {
match &distribution { match &distribution {
Ok(distribution) => { Ok(distribution) => {
report.push_result(execute( report.push_result(execute(|| distribution.upgrade(&sudo, opt.dry_run))?);
|terminal| distribution.upgrade(&sudo, terminal, opt.dry_run),
&mut execution_context,
)?);
} }
Err(e) => { Err(e) => {
println!("Error detecting current distribution: {}", e); println!("Error detecting current distribution: {}", e);
} }
} }
report.push_result(execute( report.push_result(execute(|| linux::run_etc_update(&sudo, opt.dry_run))?);
|terminal| linux::run_etc_update(&sudo, terminal, opt.dry_run),
&mut execution_context,
)?);
} }
} }
#[cfg(windows)] #[cfg(windows)]
report.push_result(execute( report.push_result(execute(|| windows::run_chocolatey(opt.dry_run))?);
|terminal| windows::run_chocolatey(terminal, opt.dry_run),
&mut execution_context,
)?);
#[cfg(windows)] #[cfg(windows)]
report.push_result(execute( report.push_result(execute(|| windows::run_scoop(opt.dry_run))?);
|terminal| windows::run_scoop(terminal, opt.dry_run),
&mut execution_context,
)?);
#[cfg(unix)] #[cfg(unix)]
report.push_result(execute( report.push_result(execute(|| unix::run_homebrew(opt.cleanup, opt.dry_run))?);
|terminal| unix::run_homebrew(terminal, opt.cleanup, opt.dry_run),
&mut execution_context,
)?);
#[cfg(target_os = "freebsd")] #[cfg(target_os = "freebsd")]
report.push_result(execute( report.push_result(execute(|| freebsd::upgrade_packages(&sudo, opt.dry_run))?);
|terminal| freebsd::upgrade_packages(&sudo, terminal, opt.dry_run),
&mut execution_context,
)?);
#[cfg(unix)] #[cfg(unix)]
report.push_result(execute( report.push_result(execute(|| unix::run_nix(opt.dry_run))?);
|terminal| unix::run_nix(terminal, opt.dry_run),
&mut execution_context,
)?);
if !opt.no_emacs { if !opt.no_emacs {
git_repos.insert(base_dirs.home_dir().join(".emacs.d")); git_repos.insert(base_dirs.home_dir().join(".emacs.d"));
@@ -240,80 +205,32 @@ fn run() -> Result<(), Error> {
} }
} }
for repo in git_repos.repositories() { for repo in git_repos.repositories() {
report.push_result(execute( report.push_result(execute(|| git.pull(&repo, opt.dry_run))?);
|terminal| git.pull(&repo, terminal, opt.dry_run),
&mut execution_context,
)?);
} }
#[cfg(unix)] #[cfg(unix)]
{ {
report.push_result(execute( report.push_result(execute(|| unix::run_zplug(&base_dirs, opt.dry_run))?);
|terminal| unix::run_zplug(&base_dirs, terminal, opt.dry_run), report.push_result(execute(|| unix::run_fisher(&base_dirs, opt.dry_run))?);
&mut execution_context, report.push_result(execute(|| tmux::run_tpm(&base_dirs, opt.dry_run))?);
)?);
report.push_result(execute(
|terminal| unix::run_fisher(&base_dirs, terminal, opt.dry_run),
&mut execution_context,
)?);
report.push_result(execute(
|terminal| tmux::run_tpm(&base_dirs, terminal, opt.dry_run),
&mut execution_context,
)?);
} }
report.push_result(execute( report.push_result(execute(|| generic::run_rustup(&base_dirs, opt.dry_run))?);
|terminal| generic::run_rustup(&base_dirs, terminal, opt.dry_run), report.push_result(execute(|| generic::run_cargo_update(opt.dry_run))?);
&mut execution_context,
)?);
report.push_result(execute(
|terminal| generic::run_cargo_update(terminal, opt.dry_run),
&mut execution_context,
)?);
if !opt.no_emacs { if !opt.no_emacs {
report.push_result(execute( report.push_result(execute(|| generic::run_emacs(&base_dirs, opt.dry_run))?);
|terminal| generic::run_emacs(&base_dirs, terminal, opt.dry_run),
&mut execution_context,
)?);
} }
report.push_result(execute( report.push_result(execute(|| generic::run_opam_update(opt.dry_run))?);
|terminal| generic::run_opam_update(terminal, opt.dry_run), report.push_result(execute(|| generic::run_vcpkg_update(opt.dry_run))?);
&mut execution_context, report.push_result(execute(|| generic::run_pipx_update(opt.dry_run))?);
)?); report.push_result(execute(|| generic::run_jetpack(opt.dry_run))?);
report.push_result(execute( report.push_result(execute(|| vim::upgrade_vim(&base_dirs, opt.dry_run))?);
|terminal| generic::run_vcpkg_update(terminal, opt.dry_run), report.push_result(execute(|| vim::upgrade_neovim(&base_dirs, opt.dry_run))?);
&mut execution_context, report.push_result(execute(|| node::run_npm_upgrade(&base_dirs, opt.dry_run))?);
)?); report.push_result(execute(|| generic::run_composer_update(&base_dirs, opt.dry_run))?);
report.push_result(execute( report.push_result(execute(|| node::yarn_global_update(opt.dry_run))?);
|terminal| generic::run_pipx_update(terminal, opt.dry_run),
&mut execution_context,
)?);
report.push_result(execute(
|terminal| generic::run_jetpack(terminal, opt.dry_run),
&mut execution_context,
)?);
report.push_result(execute(
|terminal| vim::upgrade_vim(&base_dirs, terminal, opt.dry_run),
&mut execution_context,
)?);
report.push_result(execute(
|terminal| vim::upgrade_neovim(&base_dirs, terminal, opt.dry_run),
&mut execution_context,
)?);
report.push_result(execute(
|terminal| node::run_npm_upgrade(&base_dirs, terminal, opt.dry_run),
&mut execution_context,
)?);
report.push_result(execute(
|terminal| generic::run_composer_update(&base_dirs, terminal, opt.dry_run),
&mut execution_context,
)?);
report.push_result(execute(
|terminal| node::yarn_global_update(terminal, opt.dry_run),
&mut execution_context,
)?);
#[cfg(not(any( #[cfg(not(any(
target_os = "freebsd", target_os = "freebsd",
@@ -321,92 +238,56 @@ fn run() -> Result<(), Error> {
target_os = "netbsd", target_os = "netbsd",
target_os = "dragonfly" target_os = "dragonfly"
)))] )))]
report.push_result(execute( report.push_result(execute(|| generic::run_apm(opt.dry_run))?);
|terminal| generic::run_apm(terminal, opt.dry_run), report.push_result(execute(|| generic::run_gem(&base_dirs, opt.dry_run))?);
&mut execution_context,
)?);
report.push_result(execute(
|terminal| generic::run_gem(&base_dirs, terminal, opt.dry_run),
&mut execution_context,
)?);
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
report.push_result(execute( report.push_result(execute(|| linux::flatpak_user_update(opt.dry_run))?);
|terminal| linux::flatpak_user_update(terminal, opt.dry_run), report.push_result(execute(|| linux::flatpak_global_update(&sudo, opt.dry_run))?);
&mut execution_context, report.push_result(execute(|| linux::run_snap(&sudo, opt.dry_run))?);
)?);
report.push_result(execute(
|terminal| linux::flatpak_global_update(&sudo, terminal, opt.dry_run),
&mut execution_context,
)?);
report.push_result(execute(
|terminal| linux::run_snap(&sudo, terminal, opt.dry_run),
&mut execution_context,
)?);
} }
if let Some(commands) = config.commands() { if let Some(commands) = config.commands() {
for (name, command) in commands { for (name, command) in commands {
report.push_result(execute( report.push_result(execute(|| {
|terminal| { Some((name, generic::run_custom_command(&name, &command, opt.dry_run).is_ok()))
Some(( })?);
name,
generic::run_custom_command(&name, &command, terminal, opt.dry_run).is_ok(),
))
},
&mut execution_context,
)?);
} }
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
report.push_result(execute( report.push_result(execute(|| linux::run_fwupdmgr(opt.dry_run))?);
|terminal| linux::run_fwupdmgr(terminal, opt.dry_run), report.push_result(execute(|| linux::run_needrestart(&sudo, opt.dry_run))?);
&mut execution_context,
)?);
report.push_result(execute(
|terminal| linux::run_needrestart(&sudo, terminal, opt.dry_run),
&mut execution_context,
)?);
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
{ {
if !opt.no_system { if !opt.no_system {
report.push_result(execute( report.push_result(execute(|| macos::upgrade_macos(opt.dry_run))?);
|terminal| macos::upgrade_macos(terminal, opt.dry_run),
&mut execution_context,
)?);
} }
} }
#[cfg(target_os = "freebsd")] #[cfg(target_os = "freebsd")]
{ {
if !opt.no_system { if !opt.no_system {
report.push_result(execute( report.push_result(execute(|| freebsd::upgrade_freebsd(&sudo, opt.dry_run))?);
|terminal| freebsd::upgrade_freebsd(&sudo, terminal, opt.dry_run),
&mut execution_context,
)?);
} }
} }
#[cfg(windows)] #[cfg(windows)]
{ {
if !opt.no_system { if !opt.no_system {
report.push_result(execute( report.push_result(execute(|| powershell.windows_update(opt.dry_run))?);
|terminal| powershell.windows_update(terminal, opt.dry_run),
&mut execution_context,
)?);
} }
} }
if !report.data().is_empty() { if !report.data().is_empty() {
execution_context.terminal.print_separator("Summary"); print_separator("Summary");
for (key, succeeded) in report.data() { for (key, succeeded) in report.data() {
execution_context.terminal.print_result(key, *succeeded); print_result(key, *succeeded);
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]

View File

@@ -1,5 +1,5 @@
use super::executor::Executor; use super::executor::Executor;
use super::terminal::Terminal; use super::terminal::print_separator;
use super::utils::{which, Check, PathExt}; use super::utils::{which, Check, PathExt};
use directories::BaseDirs; use directories::BaseDirs;
use failure; use failure;
@@ -35,11 +35,11 @@ impl NPM {
} }
#[must_use] #[must_use]
pub fn run_npm_upgrade(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_npm_upgrade(base_dirs: &BaseDirs, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(npm) = which("npm").map(NPM::new) { if let Some(npm) = which("npm").map(NPM::new) {
if let Ok(npm_root) = npm.root() { if let Ok(npm_root) = npm.root() {
if npm_root.is_descendant_of(base_dirs.home_dir()) { if npm_root.is_descendant_of(base_dirs.home_dir()) {
terminal.print_separator("Node Package Manager"); print_separator("Node Package Manager");
let success = npm.upgrade(dry_run).is_ok(); let success = npm.upgrade(dry_run).is_ok();
return Some(("NPM", success)); return Some(("NPM", success));
} }
@@ -49,9 +49,9 @@ pub fn run_npm_upgrade(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: b
} }
#[must_use] #[must_use]
pub fn yarn_global_update(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn yarn_global_update(dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(yarn) = which("yarn") { if let Some(yarn) = which("yarn") {
terminal.print_separator("Yarn"); print_separator("Yarn");
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
Executor::new(&yarn, dry_run) Executor::new(&yarn, dry_run)

View File

@@ -1,4 +1,4 @@
use super::terminal::Terminal; use super::terminal::*;
use failure::Error; use failure::Error;
use self_update_crate; use self_update_crate;
#[cfg(unix)] #[cfg(unix)]
@@ -8,8 +8,8 @@ use std::os::unix::process::CommandExt;
#[cfg(unix)] #[cfg(unix)]
use std::process::Command; use std::process::Command;
pub fn self_update(terminal: &mut Terminal) -> Result<(), Error> { pub fn self_update() -> Result<(), Error> {
terminal.print_separator("Self update"); print_separator("Self update");
#[cfg(unix)] #[cfg(unix)]
let current_exe = env::current_exe(); let current_exe = env::current_exe();
@@ -35,7 +35,7 @@ pub fn self_update(terminal: &mut Terminal) -> Result<(), Error> {
#[cfg(unix)] #[cfg(unix)]
{ {
if result.updated() { if result.updated() {
terminal.print_warning("Respawning..."); print_warning("Respawning...");
let err = Command::new(current_exe?).args(env::args().skip(1)).exec(); let err = Command::new(current_exe?).args(env::args().skip(1)).exec();
Err(err)? Err(err)?
} }

View File

@@ -1,14 +1,20 @@
use console::{style, Term}; use console::{style, Term};
use lazy_static::lazy_static;
use std::cmp::{max, min}; use std::cmp::{max, min};
use std::io::{self, Write}; use std::io::{self, Write};
use std::sync::Mutex;
pub struct Terminal { lazy_static! {
static ref TERMINAL: Mutex<Terminal> = Mutex::new(Terminal::new());
}
struct Terminal {
width: Option<u16>, width: Option<u16>,
term: Term, term: Term,
} }
impl Terminal { impl Terminal {
pub fn new() -> Self { fn new() -> Self {
let term = Term::stdout(); let term = Term::stdout();
Self { Self {
width: term.size_checked().map(|(_, w)| w), width: term.size_checked().map(|(_, w)| w),
@@ -16,56 +22,59 @@ impl Terminal {
} }
} }
pub fn print_separator<P: AsRef<str>>(&mut self, message: P) { fn print_separator<P: AsRef<str>>(&mut self, message: P) {
let message = message.as_ref(); let message = message.as_ref();
match self.width { match self.width {
Some(width) => { Some(width) => {
println!( self.term
"{}", .write_fmt(format_args!(
style(format!( "{}\n",
"\n―― {} {:―^border$}", style(format_args!(
message, "\n―― {} {:―^border$}",
"", message,
border = max(2, min(80, width as usize) - 3 - message.len()) "",
)).bold() border = max(2, min(80, width as usize) - 3 - message.len())
.white() )).bold()
); .white()
)).ok();
} }
None => { None => {
println!("―― {} ――", message); self.term.write_fmt(format_args!("―― {} ――\n", message)).ok();
} }
} }
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn print_warning<P: AsRef<str>>(&mut self, message: P) { fn print_warning<P: AsRef<str>>(&mut self, message: P) {
let message = message.as_ref(); let message = message.as_ref();
println!("{}", style(message).yellow().bold()); self.term
.write_fmt(format_args!("{}\n", style(message).yellow().bold()))
.ok();
} }
pub fn print_result<P: AsRef<str>>(&mut self, key: P, succeeded: bool) { fn print_result<P: AsRef<str>>(&mut self, key: P, succeeded: bool) {
let key = key.as_ref(); let key = key.as_ref();
println!( self.term
"{}: {}", .write_fmt(format_args!(
key, "{}: {}\n",
if succeeded { key,
style("OK").bold().green() if succeeded {
} else { style("OK").bold().green()
style("FAILED").bold().red() } else {
} style("FAILED").bold().red()
); }
)).ok();
} }
pub fn should_retry(&mut self, running: bool) -> Result<bool, io::Error> { fn should_retry(&mut self, running: bool) -> Result<bool, io::Error> {
if self.width.is_none() { if self.width.is_none() {
return Ok(false); return Ok(false);
} }
println!();
self.term self.term
.write_fmt(format_args!( .write_fmt(format_args!(
"{}", "\n{}",
style(format!( style(format!(
"Retry? [y/N] {}", "Retry? [y/N] {}",
if !running { if !running {
@@ -85,7 +94,8 @@ impl Terminal {
} }
}; };
println!(); self.term.write_str("\n").ok();
answer answer
} }
} }
@@ -95,3 +105,19 @@ impl Default for Terminal {
Self::new() Self::new()
} }
} }
pub fn should_retry(running: bool) -> Result<bool, io::Error> {
TERMINAL.lock().unwrap().should_retry(running)
}
pub fn print_separator<P: AsRef<str>>(message: P) {
TERMINAL.lock().unwrap().print_separator(message)
}
pub fn print_warning<P: AsRef<str>>(message: P) {
TERMINAL.lock().unwrap().print_warning(message)
}
pub fn print_result<P: AsRef<str>>(key: P, succeeded: bool) {
TERMINAL.lock().unwrap().print_result(key, succeeded)
}

View File

@@ -1,5 +1,5 @@
use super::executor::Executor; use super::executor::Executor;
use super::terminal::Terminal; use super::terminal::print_separator;
use super::utils::which; use super::utils::which;
use super::utils::{Check, PathExt}; use super::utils::{Check, PathExt};
use directories::BaseDirs; use directories::BaseDirs;
@@ -10,13 +10,13 @@ use std::os::unix::process::CommandExt;
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
pub fn run_tpm(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_tpm(base_dirs: &BaseDirs, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(tpm) = base_dirs if let Some(tpm) = base_dirs
.home_dir() .home_dir()
.join(".tmux/plugins/tpm/bin/update_plugins") .join(".tmux/plugins/tpm/bin/update_plugins")
.if_exists() .if_exists()
{ {
terminal.print_separator("tmux plugins"); print_separator("tmux plugins");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
Executor::new(&tpm, dry_run).arg("all").spawn()?.wait()?.check()?; Executor::new(&tpm, dry_run).arg("all").spawn()?.wait()?.check()?;

View File

@@ -1,13 +1,13 @@
use super::executor::Executor; use super::executor::Executor;
use super::terminal::Terminal; use super::terminal::print_separator;
use super::utils::{which, Check}; use super::utils::{which, Check};
use directories::BaseDirs; use directories::BaseDirs;
use failure::Error; use failure::Error;
pub fn run_zplug(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_zplug(base_dirs: &BaseDirs, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(zsh) = which("zsh") { if let Some(zsh) = which("zsh") {
if base_dirs.home_dir().join(".zplug").exists() { if base_dirs.home_dir().join(".zplug").exists() {
terminal.print_separator("zplug"); print_separator("zplug");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
Executor::new(zsh, dry_run) Executor::new(zsh, dry_run)
@@ -25,10 +25,10 @@ pub fn run_zplug(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -
None None
} }
pub fn run_fisher(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_fisher(base_dirs: &BaseDirs, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(fish) = which("fish") { if let Some(fish) = which("fish") {
if base_dirs.home_dir().join(".config/fish/functions/fisher.fish").exists() { if base_dirs.home_dir().join(".config/fish/functions/fisher.fish").exists() {
terminal.print_separator("fisher"); print_separator("fisher");
let success = || -> Result<(), Error> { let success = || -> Result<(), Error> {
Executor::new(&fish, dry_run) Executor::new(&fish, dry_run)
@@ -52,9 +52,9 @@ pub fn run_fisher(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool)
} }
#[must_use] #[must_use]
pub fn run_homebrew(terminal: &mut Terminal, cleanup: bool, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_homebrew(cleanup: bool, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(brew) = which("brew") { if let Some(brew) = which("brew") {
terminal.print_separator("Brew"); print_separator("Brew");
let inner = || -> Result<(), Error> { let inner = || -> Result<(), Error> {
Executor::new(&brew, dry_run).arg("update").spawn()?.wait()?.check()?; Executor::new(&brew, dry_run).arg("update").spawn()?.wait()?.check()?;
@@ -72,10 +72,10 @@ pub fn run_homebrew(terminal: &mut Terminal, cleanup: bool, dry_run: bool) -> Op
} }
#[must_use] #[must_use]
pub fn run_nix(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_nix(dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(nix) = which("nix") { if let Some(nix) = which("nix") {
if let Some(nix_env) = which("nix-env") { if let Some(nix_env) = which("nix-env") {
terminal.print_separator("Nix"); print_separator("Nix");
let inner = || -> Result<(), Error> { let inner = || -> Result<(), Error> {
Executor::new(&nix, dry_run) Executor::new(&nix, dry_run)

View File

@@ -1,5 +1,5 @@
use super::executor::Executor; use super::executor::Executor;
use super::terminal::Terminal; use super::terminal::print_separator;
use super::utils::{which, Check, PathExt}; use super::utils::{which, Check, PathExt};
use directories::BaseDirs; use directories::BaseDirs;
use failure; use failure;
@@ -82,11 +82,11 @@ fn upgrade(
} }
#[must_use] #[must_use]
pub fn upgrade_vim(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn upgrade_vim(base_dirs: &BaseDirs, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(vim) = which("vim") { if let Some(vim) = which("vim") {
if let Some(vimrc) = vimrc(&base_dirs) { if let Some(vimrc) = vimrc(&base_dirs) {
if let Some(plugin_framework) = PluginFramework::detect(&vimrc) { if let Some(plugin_framework) = PluginFramework::detect(&vimrc) {
terminal.print_separator(&format!("Vim ({:?})", plugin_framework)); print_separator(&format!("Vim ({:?})", plugin_framework));
let success = upgrade(&vim, &vimrc, plugin_framework, dry_run).is_ok(); let success = upgrade(&vim, &vimrc, plugin_framework, dry_run).is_ok();
return Some(("vim", success)); return Some(("vim", success));
} }
@@ -97,11 +97,11 @@ pub fn upgrade_vim(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool)
} }
#[must_use] #[must_use]
pub fn upgrade_neovim(base_dirs: &BaseDirs, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn upgrade_neovim(base_dirs: &BaseDirs, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(nvim) = which("nvim") { if let Some(nvim) = which("nvim") {
if let Some(nvimrc) = nvimrc(&base_dirs) { if let Some(nvimrc) = nvimrc(&base_dirs) {
if let Some(plugin_framework) = PluginFramework::detect(&nvimrc) { if let Some(plugin_framework) = PluginFramework::detect(&nvimrc) {
terminal.print_separator(&format!("Neovim ({:?})", plugin_framework)); print_separator(&format!("Neovim ({:?})", plugin_framework));
let success = upgrade(&nvim, &nvimrc, plugin_framework, dry_run).is_ok(); let success = upgrade(&nvim, &nvimrc, plugin_framework, dry_run).is_ok();
return Some(("Neovim", success)); return Some(("Neovim", success));
} }

View File

@@ -1,5 +1,5 @@
use super::executor::Executor; use super::executor::Executor;
use super::terminal::Terminal; use super::terminal::print_separator;
use super::utils::{self, which, Check}; use super::utils::{self, which, Check};
use failure; use failure;
use log::error; use log::error;
@@ -7,9 +7,9 @@ use std::path::PathBuf;
use std::process::Command; use std::process::Command;
#[must_use] #[must_use]
pub fn run_chocolatey(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_chocolatey(dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(choco) = utils::which("choco") { if let Some(choco) = utils::which("choco") {
terminal.print_separator("Chocolatey"); print_separator("Chocolatey");
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
Executor::new(&choco, dry_run) Executor::new(&choco, dry_run)
@@ -27,9 +27,9 @@ pub fn run_chocolatey(terminal: &mut Terminal, dry_run: bool) -> Option<(&'stati
} }
#[must_use] #[must_use]
pub fn run_scoop(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn run_scoop(dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(scoop) = utils::which("scoop") { if let Some(scoop) = utils::which("scoop") {
terminal.print_separator("Scoop"); print_separator("Scoop");
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
Executor::new(&scoop, dry_run) Executor::new(&scoop, dry_run)
@@ -91,9 +91,9 @@ impl Powershell {
} }
#[must_use] #[must_use]
pub fn update_modules(&self, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn update_modules(&self, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(powershell) = &self.path { if let Some(powershell) = &self.path {
terminal.print_separator("Powershell Modules Update"); print_separator("Powershell Modules Update");
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
Executor::new(&powershell, dry_run) Executor::new(&powershell, dry_run)
@@ -111,10 +111,10 @@ impl Powershell {
} }
#[must_use] #[must_use]
pub fn windows_update(&self, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { pub fn windows_update(&self, dry_run: bool) -> Option<(&'static str, bool)> {
if let Some(powershell) = &self.path { if let Some(powershell) = &self.path {
if Self::has_command(&powershell, "Install-WindowsUpdate") { if Self::has_command(&powershell, "Install-WindowsUpdate") {
terminal.print_separator("Windows Update"); print_separator("Windows Update");
let success = || -> Result<(), failure::Error> { let success = || -> Result<(), failure::Error> {
Executor::new(&powershell, dry_run) Executor::new(&powershell, dry_run)