Remove execute legacy

This commit is contained in:
Roey Darwish Dror
2019-03-10 21:48:49 +02:00
parent 12bf4a51f9
commit 1095f46a8a
7 changed files with 86 additions and 135 deletions

View File

@@ -243,7 +243,12 @@ fn run() -> Result<(), Error> {
} }
} }
for repo in git_repos.repositories() { 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)] #[cfg(unix)]
@@ -260,10 +265,12 @@ fn run() -> Result<(), Error> {
|| unix::run_fisher(&base_dirs, run_type), || unix::run_fisher(&base_dirs, run_type),
config.no_retry(), config.no_retry(),
)?; )?;
report.push_result(execute_legacy( execute(
&mut report,
"tmux",
|| tmux::run_tpm(&base_dirs, run_type), || tmux::run_tpm(&base_dirs, run_type),
config.no_retry(), config.no_retry(),
)?); )?;
} }
execute( execute(
@@ -316,30 +323,38 @@ fn run() -> Result<(), Error> {
)?; )?;
if config.should_run(Step::Vim) { if config.should_run(Step::Vim) {
report.push_result(execute_legacy( execute(
&mut report,
"vim",
|| vim::upgrade_vim(&base_dirs, run_type), || vim::upgrade_vim(&base_dirs, run_type),
config.no_retry(), config.no_retry(),
)?); )?;
report.push_result(execute_legacy( execute(
&mut report,
"Neovim",
|| vim::upgrade_neovim(&base_dirs, run_type), || vim::upgrade_neovim(&base_dirs, run_type),
config.no_retry(), config.no_retry(),
)?); )?;
} }
report.push_result(execute_legacy( execute(
&mut report,
"NPM",
|| node::run_npm_upgrade(&base_dirs, run_type), || node::run_npm_upgrade(&base_dirs, run_type),
config.no_retry(), config.no_retry(),
)?); )?;
execute( execute(
&mut report, &mut report,
"composer", "composer",
|| generic::run_composer_update(&base_dirs, run_type), || generic::run_composer_update(&base_dirs, run_type),
config.no_retry(), config.no_retry(),
)?; )?;
report.push_result(execute_legacy( execute(
&mut report,
"yarn",
|| node::yarn_global_update(run_type), || node::yarn_global_update(run_type),
config.no_retry(), config.no_retry(),
)?); )?;
#[cfg(not(any( #[cfg(not(any(
target_os = "freebsd", target_os = "freebsd",
@@ -402,7 +417,12 @@ fn run() -> Result<(), Error> {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
{ {
if config.should_run(Step::System) { 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(),
)?;
} }
} }

View File

@@ -55,25 +55,18 @@ impl Git {
None None
} }
pub fn pull<P: AsRef<Path>>(&self, path: P, run_type: RunType) -> Option<(String, bool)> { pub fn pull<P: AsRef<Path>>(&self, path: P, run_type: RunType) -> Result<(), Error> {
let path = path.as_ref(); let path = path.as_ref();
print_separator(format!("Pulling {}", HumanizedPath::from(path))); print_separator(format!("Pulling {}", HumanizedPath::from(path)));
let git = self.git.as_ref().unwrap(); let git = self.git.as_ref().unwrap();
let success = || -> Result<(), Error> { run_type
run_type .execute(git)
.execute(git) .args(&["pull", "--rebase", "--autostash"])
.args(&["pull", "--rebase", "--autostash"]) .current_dir(&path)
.current_dir(&path) .check_run()
.check_run()?;
Ok(())
}()
.is_ok();
Some((format!("git: {}", HumanizedPath::from(path)), success))
} }
} }

View File

@@ -1,7 +1,7 @@
use crate::error::Error; use crate::error::{Error, ErrorKind};
use crate::executor::{CommandExt, RunType}; use crate::executor::{CommandExt, RunType};
use crate::terminal::print_separator; use crate::terminal::print_separator;
use crate::utils::{which, PathExt}; use crate::utils::{require, PathExt};
use directories::BaseDirs; use directories::BaseDirs;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
@@ -29,33 +29,20 @@ impl NPM {
} }
} }
#[must_use] pub fn run_npm_upgrade(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
pub fn run_npm_upgrade(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> { let npm = require("npm").map(NPM::new)?;
if let Some(npm) = which("npm").map(NPM::new) { let 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()) { Err(ErrorKind::SkipStep)?;
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));
} }
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()
} }

View File

@@ -5,43 +5,19 @@ use failure::ResultExt;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
#[must_use] pub fn upgrade_freebsd(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
pub fn upgrade_freebsd(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'static str, bool)> { let sudo = require_option(sudo)?;
print_separator("FreeBSD Update"); print_separator("FreeBSD Update");
run_type
if let Some(sudo) = sudo { .execute(sudo)
let success = || -> Result<(), Error> { .args(&["/usr/sbin/freebsd-update", "fetch", "install"])
run_type .check_run()
.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
}
} }
#[must_use] pub fn upgrade_packages(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
pub fn upgrade_packages(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'static str, bool)> { let sudo = require_option(sudo)?;
print_separator("FreeBSD Packages"); print_separator("FreeBSD Packages");
run_type.execute(sudo).args(&["/usr/sbin/pkg", "upgrade"]).check_run()
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
}
} }
pub fn audit_packages(sudo: &Option<PathBuf>) -> Result<(), Error> { pub fn audit_packages(sudo: &Option<PathBuf>) -> Result<(), Error> {

View File

@@ -3,17 +3,11 @@ use crate::executor::RunType;
use crate::terminal::print_separator; use crate::terminal::print_separator;
#[must_use] #[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"); print_separator("App Store");
let success = || -> Result<(), Error> { run_type
run_type .execute("softwareupdate")
.execute("softwareupdate") .args(&["--install", "--all"])
.args(&["--install", "--all"]) .check_run()
.check_run()?;
Ok(())
}()
.is_ok();
Some(("App Store", success))
} }

View File

@@ -10,24 +10,15 @@ 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, run_type: RunType) -> Option<(&'static str, bool)> { pub fn run_tpm(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
if let Some(tpm) = base_dirs let tpm = base_dirs
.home_dir() .home_dir()
.join(".tmux/plugins/tpm/bin/update_plugins") .join(".tmux/plugins/tpm/bin/update_plugins")
.if_exists() .require()?;
{
print_separator("tmux plugins");
let success = || -> Result<(), Error> { print_separator("tmux plugins");
run_type.execute(&tpm).arg("all").check_run()?;
Ok(())
}()
.is_ok();
return Some(("tmux", success)); run_type.execute(&tpm).arg("all").check_run()
}
None
} }
fn has_session(tmux: &Path, session_name: &str) -> Result<bool, io::Error> { fn has_session(tmux: &Path, session_name: &str) -> Result<bool, io::Error> {

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, PathExt}; use crate::utils::{require, require_option, PathExt};
use directories::BaseDirs; use directories::BaseDirs;
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
@@ -77,31 +77,21 @@ fn upgrade(vim: &PathBuf, vimrc: &PathBuf, plugin_framework: PluginFramework, ru
} }
#[must_use] #[must_use]
pub fn upgrade_vim(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> { pub fn upgrade_vim(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
if let Some(vim) = which("vim") { let vim = require("vim")?;
if let Some(vimrc) = vimrc(&base_dirs) { let vimrc = require_option(vimrc(&base_dirs))?;
if let Some(plugin_framework) = PluginFramework::detect(&vimrc) { let plugin_framework = require_option(PluginFramework::detect(&vimrc))?;
print_separator(&format!("Vim ({:?})", plugin_framework));
let success = upgrade(&vim, &vimrc, plugin_framework, run_type).is_ok();
return Some(("vim", success));
}
}
}
None print_separator(&format!("Vim ({:?})", plugin_framework));
upgrade(&vim, &vimrc, plugin_framework, run_type)
} }
#[must_use] #[must_use]
pub fn upgrade_neovim(base_dirs: &BaseDirs, run_type: RunType) -> Option<(&'static str, bool)> { pub fn upgrade_neovim(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
if let Some(nvim) = which("nvim") { let nvim = require("nvim")?;
if let Some(nvimrc) = nvimrc(&base_dirs) { let nvimrc = require_option(nvimrc(&base_dirs))?;
if let Some(plugin_framework) = PluginFramework::detect(&nvimrc) { let plugin_framework = require_option(PluginFramework::detect(&nvimrc))?;
print_separator(&format!("Neovim ({:?})", plugin_framework));
let success = upgrade(&nvim, &nvimrc, plugin_framework, run_type).is_ok();
return Some(("Neovim", success));
}
}
}
None print_separator(&format!("Neovim ({:?})", plugin_framework));
upgrade(&nvim, &nvimrc, plugin_framework, run_type)
} }