Remove execute legacy
This commit is contained in:
44
src/main.rs
44
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(),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,25 +55,18 @@ impl Git {
|
||||
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();
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -5,43 +5,19 @@ use failure::ResultExt;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
#[must_use]
|
||||
pub fn upgrade_freebsd(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'static str, bool)> {
|
||||
pub fn upgrade_freebsd(sudo: &Option<PathBuf>, 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<PathBuf>, run_type: RunType) -> Option<(&'static str, bool)> {
|
||||
pub fn upgrade_packages(sudo: &Option<PathBuf>, 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<PathBuf>) -> Result<(), Error> {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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<bool, io::Error> {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user