diff --git a/src/main.rs b/src/main.rs index a7c6a394..121d0b9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -243,7 +243,12 @@ fn run() -> Result<(), Error> { } } for repo in git_repos.repositories() { - report.push_result(execute_legacy(|| git.pull(&repo, run_type), config.no_retry())?); + execute( + &mut report, + format!("git: {}", utils::HumanizedPath::from(std::path::Path::new(&repo))), + || git.pull(&repo, run_type), + config.no_retry(), + )?; } #[cfg(unix)] @@ -260,10 +265,12 @@ fn run() -> Result<(), Error> { || unix::run_fisher(&base_dirs, run_type), config.no_retry(), )?; - report.push_result(execute_legacy( + execute( + &mut report, + "tmux", || tmux::run_tpm(&base_dirs, run_type), config.no_retry(), - )?); + )?; } execute( @@ -316,30 +323,38 @@ fn run() -> Result<(), Error> { )?; if config.should_run(Step::Vim) { - report.push_result(execute_legacy( + execute( + &mut report, + "vim", || vim::upgrade_vim(&base_dirs, run_type), config.no_retry(), - )?); - report.push_result(execute_legacy( + )?; + execute( + &mut report, + "Neovim", || vim::upgrade_neovim(&base_dirs, run_type), config.no_retry(), - )?); + )?; } - report.push_result(execute_legacy( + execute( + &mut report, + "NPM", || node::run_npm_upgrade(&base_dirs, run_type), config.no_retry(), - )?); + )?; execute( &mut report, "composer", || generic::run_composer_update(&base_dirs, run_type), config.no_retry(), )?; - report.push_result(execute_legacy( + execute( + &mut report, + "yarn", || node::yarn_global_update(run_type), config.no_retry(), - )?); + )?; #[cfg(not(any( target_os = "freebsd", @@ -402,7 +417,12 @@ fn run() -> Result<(), Error> { #[cfg(target_os = "macos")] { if config.should_run(Step::System) { - report.push_result(execute_legacy(|| macos::upgrade_macos(run_type), config.no_retry())?); + execute( + &mut report, + "App Store", + || macos::upgrade_macos(run_type), + config.no_retry(), + )?; } } diff --git a/src/steps/git.rs b/src/steps/git.rs index 4cc5e3c8..4c066ccc 100644 --- a/src/steps/git.rs +++ b/src/steps/git.rs @@ -55,25 +55,18 @@ impl Git { None } - pub fn pull>(&self, path: P, run_type: RunType) -> Option<(String, bool)> { + pub fn pull>(&self, path: P, run_type: RunType) -> Result<(), Error> { let path = path.as_ref(); print_separator(format!("Pulling {}", HumanizedPath::from(path))); let git = self.git.as_ref().unwrap(); - let success = || -> Result<(), Error> { - run_type - .execute(git) - .args(&["pull", "--rebase", "--autostash"]) - .current_dir(&path) - .check_run()?; - - Ok(()) - }() - .is_ok(); - - Some((format!("git: {}", HumanizedPath::from(path)), success)) + run_type + .execute(git) + .args(&["pull", "--rebase", "--autostash"]) + .current_dir(&path) + .check_run() } } diff --git a/src/steps/node.rs b/src/steps/node.rs index b2f6e702..254edc34 100644 --- a/src/steps/node.rs +++ b/src/steps/node.rs @@ -1,7 +1,7 @@ -use crate::error::Error; +use crate::error::{Error, ErrorKind}; use crate::executor::{CommandExt, RunType}; use crate::terminal::print_separator; -use crate::utils::{which, PathExt}; +use crate::utils::{require, PathExt}; use directories::BaseDirs; use std::path::PathBuf; use std::process::Command; @@ -29,33 +29,20 @@ impl NPM { } } -#[must_use] -pub fn run_npm_upgrade(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> { - if let Some(npm) = which("npm").map(NPM::new) { - if let Ok(npm_root) = npm.root() { - if npm_root.is_descendant_of(base_dirs.home_dir()) { - print_separator("Node Package Manager"); - let success = npm.upgrade(run_type).is_ok(); - return Some(("NPM", success)); - } - } - } - None -} - -#[must_use] -pub fn yarn_global_update(run_type: RunType) -> Option<(&'static str, bool)> { - if let Some(yarn) = which("yarn") { - print_separator("Yarn"); - - let success = || -> Result<(), Error> { - run_type.execute(&yarn).args(&["global", "upgrade", "-s"]).check_run()?; - Ok(()) - }() - .is_ok(); - - return Some(("yarn", success)); +pub fn run_npm_upgrade(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> { + let npm = require("npm").map(NPM::new)?; + let npm_root = npm.root()?; + if !npm_root.is_descendant_of(base_dirs.home_dir()) { + Err(ErrorKind::SkipStep)?; } - None + print_separator("Node Package Manager"); + npm.upgrade(run_type) +} + +pub fn yarn_global_update(run_type: RunType) -> Result<(), Error> { + let yarn = require("yarn")?; + + print_separator("Yarn"); + run_type.execute(&yarn).args(&["global", "upgrade", "-s"]).check_run() } diff --git a/src/steps/os/freebsd.rs b/src/steps/os/freebsd.rs index 8b7c6e1b..9f390c17 100644 --- a/src/steps/os/freebsd.rs +++ b/src/steps/os/freebsd.rs @@ -5,43 +5,19 @@ use failure::ResultExt; use std::path::PathBuf; use std::process::Command; -#[must_use] -pub fn upgrade_freebsd(sudo: &Option, run_type: RunType) -> Option<(&'static str, bool)> { +pub fn upgrade_freebsd(sudo: &Option, run_type: RunType) -> Result<(), Error> { + let sudo = require_option(sudo)?; print_separator("FreeBSD Update"); - - if let Some(sudo) = sudo { - let success = || -> Result<(), Error> { - run_type - .execute(sudo) - .args(&["/usr/sbin/freebsd-update", "fetch", "install"]) - .check_run()?; - Ok(()) - }() - .is_ok(); - - Some(("FreeBSD Update", success)) - } else { - print_warning("No sudo or yay detected. Skipping system upgrade"); - None - } + run_type + .execute(sudo) + .args(&["/usr/sbin/freebsd-update", "fetch", "install"]) + .check_run() } -#[must_use] -pub fn upgrade_packages(sudo: &Option, run_type: RunType) -> Option<(&'static str, bool)> { +pub fn upgrade_packages(sudo: &Option, run_type: RunType) -> Result<(), Error> { + let sudo = require_option(sudo)?; print_separator("FreeBSD Packages"); - - if let Some(sudo) = sudo { - let success = || -> Result<(), Error> { - run_type.execute(sudo).args(&["/usr/sbin/pkg", "upgrade"]).check_run()?; - Ok(()) - }() - .is_ok(); - - Some(("FreeBSD Packages", success)) - } else { - print_warning("No sudo or yay detected. Skipping package upgrade"); - None - } + run_type.execute(sudo).args(&["/usr/sbin/pkg", "upgrade"]).check_run() } pub fn audit_packages(sudo: &Option) -> Result<(), Error> { diff --git a/src/steps/os/macos.rs b/src/steps/os/macos.rs index b8b5dc8f..150e3c2d 100644 --- a/src/steps/os/macos.rs +++ b/src/steps/os/macos.rs @@ -3,17 +3,11 @@ use crate::executor::RunType; use crate::terminal::print_separator; #[must_use] -pub fn upgrade_macos(run_type: RunType) -> Option<(&'static str, bool)> { +pub fn upgrade_macos(run_type: RunType) -> Result<(), Error> { print_separator("App Store"); - let success = || -> Result<(), Error> { - run_type - .execute("softwareupdate") - .args(&["--install", "--all"]) - .check_run()?; - Ok(()) - }() - .is_ok(); - - Some(("App Store", success)) + run_type + .execute("softwareupdate") + .args(&["--install", "--all"]) + .check_run() } diff --git a/src/steps/tmux.rs b/src/steps/tmux.rs index 60dff9b6..b51e432e 100644 --- a/src/steps/tmux.rs +++ b/src/steps/tmux.rs @@ -10,24 +10,15 @@ use std::os::unix::process::CommandExt; use std::path::Path; use std::process::Command; -pub fn run_tpm(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> { - if let Some(tpm) = base_dirs +pub fn run_tpm(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> { + let tpm = base_dirs .home_dir() .join(".tmux/plugins/tpm/bin/update_plugins") - .if_exists() - { - print_separator("tmux plugins"); + .require()?; - let success = || -> Result<(), Error> { - run_type.execute(&tpm).arg("all").check_run()?; - Ok(()) - }() - .is_ok(); + print_separator("tmux plugins"); - return Some(("tmux", success)); - } - - None + run_type.execute(&tpm).arg("all").check_run() } fn has_session(tmux: &Path, session_name: &str) -> Result { diff --git a/src/steps/vim.rs b/src/steps/vim.rs index 045541f9..31ac13d0 100644 --- a/src/steps/vim.rs +++ b/src/steps/vim.rs @@ -1,7 +1,7 @@ use crate::error::Error; use crate::executor::RunType; use crate::terminal::print_separator; -use crate::utils::{which, PathExt}; +use crate::utils::{require, require_option, PathExt}; use directories::BaseDirs; use std::fs; use std::path::PathBuf; @@ -77,31 +77,21 @@ fn upgrade(vim: &PathBuf, vimrc: &PathBuf, plugin_framework: PluginFramework, ru } #[must_use] -pub fn upgrade_vim(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> { - if let Some(vim) = which("vim") { - if let Some(vimrc) = vimrc(&base_dirs) { - if let Some(plugin_framework) = PluginFramework::detect(&vimrc) { - print_separator(&format!("Vim ({:?})", plugin_framework)); - let success = upgrade(&vim, &vimrc, plugin_framework, run_type).is_ok(); - return Some(("vim", success)); - } - } - } +pub fn upgrade_vim(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> { + let vim = require("vim")?; + let vimrc = require_option(vimrc(&base_dirs))?; + let plugin_framework = require_option(PluginFramework::detect(&vimrc))?; - None + print_separator(&format!("Vim ({:?})", plugin_framework)); + upgrade(&vim, &vimrc, plugin_framework, run_type) } #[must_use] -pub fn upgrade_neovim(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> { - if let Some(nvim) = which("nvim") { - if let Some(nvimrc) = nvimrc(&base_dirs) { - if let Some(plugin_framework) = PluginFramework::detect(&nvimrc) { - print_separator(&format!("Neovim ({:?})", plugin_framework)); - let success = upgrade(&nvim, &nvimrc, plugin_framework, run_type).is_ok(); - return Some(("Neovim", success)); - } - } - } +pub fn upgrade_neovim(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> { + let nvim = require("nvim")?; + let nvimrc = require_option(nvimrc(&base_dirs))?; + let plugin_framework = require_option(PluginFramework::detect(&nvimrc))?; - None + print_separator(&format!("Neovim ({:?})", plugin_framework)); + upgrade(&nvim, &nvimrc, plugin_framework, run_type) }