Migrate from failure to anyhow/thiserror (#273)
This commit is contained in:
committed by
GitHub
parent
1ea9b91e11
commit
ba516aa1dd
@@ -1,7 +1,7 @@
|
||||
use crate::error::Error;
|
||||
use crate::executor::RunType;
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::{require, require_option, PathExt};
|
||||
use anyhow::Result;
|
||||
use directories::BaseDirs;
|
||||
#[cfg(windows)]
|
||||
use std::env;
|
||||
@@ -35,7 +35,7 @@ impl Emacs {
|
||||
self.directory.as_ref()
|
||||
}
|
||||
|
||||
pub fn upgrade(&self, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn upgrade(&self, run_type: RunType) -> Result<()> {
|
||||
let emacs = require("emacs")?;
|
||||
let init_file = require_option(self.directory.as_ref())?.join("init.el").require()?;
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::error::SkipStep;
|
||||
use crate::executor::{CommandExt, RunType};
|
||||
use crate::terminal::{print_separator, shell};
|
||||
use crate::utils::{self, PathExt};
|
||||
use anyhow::Result;
|
||||
use directories::BaseDirs;
|
||||
use failure::ResultExt;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn run_cargo_update(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_cargo_update(run_type: RunType) -> Result<()> {
|
||||
let cargo_update = utils::require("cargo-install-update")?;
|
||||
|
||||
print_separator("Cargo");
|
||||
@@ -19,14 +19,14 @@ pub fn run_cargo_update(run_type: RunType) -> Result<(), Error> {
|
||||
.check_run()
|
||||
}
|
||||
|
||||
pub fn run_flutter_upgrade(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_flutter_upgrade(run_type: RunType) -> Result<()> {
|
||||
let flutter = utils::require("flutter")?;
|
||||
|
||||
print_separator("Flutter");
|
||||
run_type.execute(&flutter).arg("upgrade").check_run()
|
||||
}
|
||||
|
||||
pub fn run_go(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_go(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let go = utils::require("go")?;
|
||||
env::var("GOPATH")
|
||||
.unwrap_or_else(|_| base_dirs.home_dir().join("go").to_str().unwrap().to_string())
|
||||
@@ -36,7 +36,7 @@ pub fn run_go(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
run_type.execute(&go).arg("get").arg("-u").arg("all").check_run()
|
||||
}
|
||||
|
||||
pub fn run_gem(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_gem(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let gem = utils::require("gem")?;
|
||||
base_dirs.home_dir().join(".gem").require()?;
|
||||
|
||||
@@ -51,7 +51,7 @@ pub fn run_gem(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
target_os = "netbsd",
|
||||
target_os = "dragonfly"
|
||||
)))]
|
||||
pub fn run_apm(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_apm(run_type: RunType) -> Result<()> {
|
||||
let apm = utils::require("apm")?;
|
||||
|
||||
print_separator("Atom Package Manager");
|
||||
@@ -59,23 +59,19 @@ pub fn run_apm(run_type: RunType) -> Result<(), Error> {
|
||||
run_type.execute(&apm).args(&["upgrade", "--confirm=false"]).check_run()
|
||||
}
|
||||
|
||||
pub fn run_rustup(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_rustup(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let rustup = utils::require("rustup")?;
|
||||
|
||||
print_separator("rustup");
|
||||
|
||||
if rustup
|
||||
.canonicalize()
|
||||
.context(ErrorKind::StepFailed)?
|
||||
.is_descendant_of(base_dirs.home_dir())
|
||||
{
|
||||
if rustup.canonicalize()?.is_descendant_of(base_dirs.home_dir()) {
|
||||
run_type.execute(&rustup).args(&["self", "update"]).check_run()?;
|
||||
}
|
||||
|
||||
run_type.execute(&rustup).arg("update").check_run()
|
||||
}
|
||||
|
||||
pub fn run_jetpack(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_jetpack(run_type: RunType) -> Result<()> {
|
||||
let jetpack = utils::require("jetpack")?;
|
||||
|
||||
print_separator("Jetpack");
|
||||
@@ -83,7 +79,7 @@ pub fn run_jetpack(run_type: RunType) -> Result<(), Error> {
|
||||
run_type.execute(&jetpack).args(&["global", "update"]).check_run()
|
||||
}
|
||||
|
||||
pub fn run_opam_update(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_opam_update(run_type: RunType) -> Result<()> {
|
||||
let opam = utils::require("opam")?;
|
||||
|
||||
print_separator("OCaml Package Manager");
|
||||
@@ -92,28 +88,28 @@ pub fn run_opam_update(run_type: RunType) -> Result<(), Error> {
|
||||
run_type.execute(&opam).arg("upgrade").check_run()
|
||||
}
|
||||
|
||||
pub fn run_vcpkg_update(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_vcpkg_update(run_type: RunType) -> Result<()> {
|
||||
let vcpkg = utils::require("vcpkg")?;
|
||||
print_separator("vcpkg");
|
||||
|
||||
run_type.execute(&vcpkg).args(&["upgrade", "--no-dry-run"]).check_run()
|
||||
}
|
||||
|
||||
pub fn run_pipx_update(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_pipx_update(run_type: RunType) -> Result<()> {
|
||||
let pipx = utils::require("pipx")?;
|
||||
print_separator("pipx");
|
||||
|
||||
run_type.execute(&pipx).arg("upgrade-all").check_run()
|
||||
}
|
||||
|
||||
pub fn run_stack_update(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_stack_update(run_type: RunType) -> Result<()> {
|
||||
let stack = utils::require("stack")?;
|
||||
print_separator("stack");
|
||||
|
||||
run_type.execute(&stack).arg("upgrade").check_run()
|
||||
}
|
||||
|
||||
pub fn run_myrepos_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_myrepos_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let myrepos = utils::require("mr")?;
|
||||
base_dirs.home_dir().join(".mrconfig").require()?;
|
||||
|
||||
@@ -133,22 +129,22 @@ pub fn run_myrepos_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<(),
|
||||
.check_run()
|
||||
}
|
||||
|
||||
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<()> {
|
||||
print_separator(name);
|
||||
run_type.execute(shell()).arg("-c").arg(command).check_run()
|
||||
}
|
||||
|
||||
pub fn run_composer_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_composer_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let composer = utils::require("composer")?;
|
||||
let composer_home = Command::new(&composer)
|
||||
.args(&["global", "config", "--absolute", "--quiet", "home"])
|
||||
.check_output()
|
||||
.map_err(|_| Error::from(ErrorKind::SkipStep))
|
||||
.map(|s| PathBuf::from(s.trim()))
|
||||
.and_then(PathExt::require)?;
|
||||
.map_err(|_| (SkipStep))
|
||||
.map(|s| PathBuf::from(s.trim()))?
|
||||
.require()?;
|
||||
|
||||
if !composer_home.is_descendant_of(base_dirs.home_dir()) {
|
||||
return Err(ErrorKind::SkipStep.into());
|
||||
return Err(SkipStep.into());
|
||||
}
|
||||
|
||||
print_separator("Composer");
|
||||
@@ -168,14 +164,14 @@ pub fn run_remote_topgrade(
|
||||
ssh_arguments: &Option<String>,
|
||||
run_in_tmux: bool,
|
||||
_tmux_arguments: &Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
) -> Result<()> {
|
||||
let ssh = utils::require("ssh")?;
|
||||
|
||||
if run_in_tmux && !run_type.dry() {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
crate::tmux::run_remote_topgrade(hostname, &ssh, _tmux_arguments)?;
|
||||
Err(ErrorKind::SkipStep.into())
|
||||
Err(SkipStep.into())
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::error::TopgradeError;
|
||||
use crate::executor::{CommandExt, RunType};
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::{which, HumanizedPath};
|
||||
use anyhow::Result;
|
||||
use console::style;
|
||||
use futures::future::{join_all, Future};
|
||||
use glob::{glob_with, MatchOptions};
|
||||
@@ -79,7 +80,7 @@ impl Git {
|
||||
repositories: &Repositories,
|
||||
run_type: RunType,
|
||||
extra_arguments: &Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
) -> Result<()> {
|
||||
if repositories.repositories.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -143,7 +144,7 @@ impl Git {
|
||||
println!("{} {}", style("Up-to-date").green().bold(), path);
|
||||
}
|
||||
}
|
||||
Ok(true) as Result<bool, Error>
|
||||
Ok(true) as Result<bool>
|
||||
} else {
|
||||
println!("{} pulling {}", style("Failed").red().bold(), path);
|
||||
if let Ok(text) = std::str::from_utf8(&output.stderr) {
|
||||
@@ -163,7 +164,7 @@ impl Git {
|
||||
let mut runtime = Runtime::new().unwrap();
|
||||
let results: Vec<bool> = runtime.block_on(join_all(futures))?;
|
||||
if results.into_iter().any(|success| !success) {
|
||||
Err(ErrorKind::StepFailed.into())
|
||||
Err(TopgradeError::PullFailed.into())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::error::SkipStep;
|
||||
use crate::executor::{CommandExt, RunType};
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::{require, PathExt};
|
||||
use anyhow::Result;
|
||||
|
||||
use directories::BaseDirs;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
@@ -15,32 +17,32 @@ impl NPM {
|
||||
Self { command }
|
||||
}
|
||||
|
||||
fn root(&self) -> Result<PathBuf, Error> {
|
||||
fn root(&self) -> Result<PathBuf> {
|
||||
Command::new(&self.command)
|
||||
.args(&["root", "-g"])
|
||||
.check_output()
|
||||
.map(PathBuf::from)
|
||||
}
|
||||
|
||||
fn upgrade(&self, run_type: RunType) -> Result<(), Error> {
|
||||
fn upgrade(&self, run_type: RunType) -> Result<()> {
|
||||
run_type.execute(&self.command).args(&["update", "-g"]).check_run()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_npm_upgrade(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_npm_upgrade(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let npm = require("npm").map(NPM::new)?;
|
||||
let npm_root = npm.root()?;
|
||||
if !npm_root.is_descendant_of(base_dirs.home_dir()) {
|
||||
return Err(ErrorKind::SkipStep.into());
|
||||
return Err(SkipStep.into());
|
||||
}
|
||||
|
||||
print_separator("Node Package Manager");
|
||||
npm.upgrade(run_type)
|
||||
}
|
||||
|
||||
pub fn yarn_global_update(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn yarn_global_update(run_type: RunType) -> Result<()> {
|
||||
let yarn = require("yarn")?;
|
||||
|
||||
print_separator("Yarn");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::error::TopgradeError;
|
||||
use crate::executor::RunType;
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::require_option;
|
||||
@@ -6,7 +6,7 @@ use failure::ResultExt;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn upgrade_packages(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn upgrade_packages(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {
|
||||
let sudo = require_option(sudo)?;
|
||||
print_separator("DrgaonFly BSD Packages");
|
||||
run_type
|
||||
@@ -15,7 +15,7 @@ pub fn upgrade_packages(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(),
|
||||
.check_run()
|
||||
}
|
||||
|
||||
pub fn audit_packages(sudo: &Option<PathBuf>) -> Result<(), Error> {
|
||||
pub fn audit_packages(sudo: &Option<PathBuf>) -> Result<()> {
|
||||
if let Some(sudo) = sudo {
|
||||
println!();
|
||||
Command::new(sudo)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::error::TopgradeError;
|
||||
use crate::executor::RunType;
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::require_option;
|
||||
@@ -6,7 +6,7 @@ use failure::ResultExt;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn upgrade_freebsd(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn upgrade_freebsd(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {
|
||||
let sudo = require_option(sudo)?;
|
||||
print_separator("FreeBSD Update");
|
||||
run_type
|
||||
@@ -15,13 +15,13 @@ pub fn upgrade_freebsd(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(),
|
||||
.check_run()
|
||||
}
|
||||
|
||||
pub fn upgrade_packages(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn upgrade_packages(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {
|
||||
let sudo = require_option(sudo)?;
|
||||
print_separator("FreeBSD Packages");
|
||||
run_type.execute(sudo).args(&["/usr/sbin/pkg", "upgrade"]).check_run()
|
||||
}
|
||||
|
||||
pub fn audit_packages(sudo: &Option<PathBuf>) -> Result<(), Error> {
|
||||
pub fn audit_packages(sudo: &Option<PathBuf>) -> Result<()> {
|
||||
if let Some(sudo) = sudo {
|
||||
println!();
|
||||
Command::new(sudo)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::config::Config;
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::error::{SkipStep, TopgradeError};
|
||||
use crate::executor::{ExecutorExitStatus, RunType};
|
||||
use crate::terminal::{print_separator, print_warning};
|
||||
use crate::utils::{require, require_option, which, PathExt};
|
||||
use failure::ResultExt;
|
||||
use anyhow::Result;
|
||||
use ini::Ini;
|
||||
use log::debug;
|
||||
use serde::Deserialize;
|
||||
@@ -37,7 +37,7 @@ pub enum Distribution {
|
||||
}
|
||||
|
||||
impl Distribution {
|
||||
fn parse_os_release(os_release: &ini::Ini) -> Result<Self, Error> {
|
||||
fn parse_os_release(os_release: &ini::Ini) -> Result<Self> {
|
||||
let section = os_release.general_section();
|
||||
let id = section.get("ID").map(String::as_str);
|
||||
let id_like: Option<Vec<&str>> = section
|
||||
@@ -65,22 +65,22 @@ impl Distribution {
|
||||
Some("gentoo") => Distribution::Gentoo,
|
||||
Some("exherbo") => Distribution::Exherbo,
|
||||
Some("nixos") => Distribution::NixOS,
|
||||
_ => return Err(ErrorKind::UnknownLinuxDistribution.into()),
|
||||
_ => return Err(TopgradeError::UnknownLinuxDistribution.into()),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn detect() -> Result<Self, Error> {
|
||||
pub fn detect() -> Result<Self> {
|
||||
if PathBuf::from(OS_RELEASE_PATH).exists() {
|
||||
let os_release = Ini::load_from_file(OS_RELEASE_PATH).context(ErrorKind::UnknownLinuxDistribution)?;
|
||||
let os_release = Ini::load_from_file(OS_RELEASE_PATH)?;
|
||||
|
||||
return Self::parse_os_release(&os_release);
|
||||
}
|
||||
|
||||
Err(ErrorKind::UnknownLinuxDistribution.into())
|
||||
Err(TopgradeError::UnknownLinuxDistribution.into())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn upgrade(self, sudo: &Option<PathBuf>, run_type: RunType, config: &Config) -> Result<(), Error> {
|
||||
pub fn upgrade(self, sudo: &Option<PathBuf>, run_type: RunType, config: &Config) -> Result<()> {
|
||||
print_separator("System update");
|
||||
|
||||
let yes = config.yes();
|
||||
@@ -134,7 +134,7 @@ fn upgrade_arch_linux(
|
||||
run_type: RunType,
|
||||
yes: bool,
|
||||
yay_arguments: &str,
|
||||
) -> Result<(), Error> {
|
||||
) -> Result<()> {
|
||||
let pacman = which("powerpill").unwrap_or_else(|| PathBuf::from("/usr/bin/pacman"));
|
||||
|
||||
let path = {
|
||||
@@ -197,7 +197,7 @@ fn upgrade_arch_linux(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upgrade_redhat(sudo: &Option<PathBuf>, run_type: RunType, yes: bool) -> Result<(), Error> {
|
||||
fn upgrade_redhat(sudo: &Option<PathBuf>, run_type: RunType, yes: bool) -> Result<()> {
|
||||
if let Some(sudo) = &sudo {
|
||||
let mut command = run_type.execute(&sudo);
|
||||
command
|
||||
@@ -219,7 +219,7 @@ fn upgrade_redhat(sudo: &Option<PathBuf>, run_type: RunType, yes: bool) -> Resul
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upgrade_suse(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
fn upgrade_suse(sudo: &Option<PathBuf>, run_type: RunType) -> Result<()> {
|
||||
if let Some(sudo) = &sudo {
|
||||
run_type
|
||||
.execute(&sudo)
|
||||
@@ -237,7 +237,7 @@ fn upgrade_suse(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upgrade_void(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
fn upgrade_void(sudo: &Option<PathBuf>, run_type: RunType) -> Result<()> {
|
||||
if let Some(sudo) = &sudo {
|
||||
for _ in 0..2 {
|
||||
run_type
|
||||
@@ -252,7 +252,7 @@ fn upgrade_void(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<()> {
|
||||
if let Some(sudo) = &sudo {
|
||||
if let Some(layman) = which("layman") {
|
||||
run_type.execute(&sudo).arg(layman).args(&["-s", "ALL"]).check_run()?;
|
||||
@@ -281,7 +281,7 @@ fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upgrade_debian(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType, yes: bool) -> Result<(), Error> {
|
||||
fn upgrade_debian(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType, yes: bool) -> Result<()> {
|
||||
if let Some(sudo) = &sudo {
|
||||
let apt = which("apt-fast").unwrap_or_else(|| PathBuf::from("/usr/bin/apt"));
|
||||
run_type.execute(&sudo).arg(&apt).arg("update").check_run()?;
|
||||
@@ -310,7 +310,7 @@ fn upgrade_debian(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType, yes:
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upgrade_solus(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
fn upgrade_solus(sudo: &Option<PathBuf>, run_type: RunType) -> Result<()> {
|
||||
if let Some(sudo) = &sudo {
|
||||
run_type
|
||||
.execute(&sudo)
|
||||
@@ -323,7 +323,7 @@ fn upgrade_solus(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upgrade_clearlinux(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
fn upgrade_clearlinux(sudo: &Option<PathBuf>, run_type: RunType) -> Result<()> {
|
||||
if let Some(sudo) = &sudo {
|
||||
run_type
|
||||
.execute(&sudo)
|
||||
@@ -336,7 +336,7 @@ fn upgrade_clearlinux(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), E
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upgrade_exherbo(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Result<(), Error> {
|
||||
fn upgrade_exherbo(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Result<()> {
|
||||
if let Some(sudo) = &sudo {
|
||||
run_type.execute(&sudo).args(&["/usr/bin/cave", "sync"]).check_run()?;
|
||||
|
||||
@@ -368,7 +368,7 @@ fn upgrade_exherbo(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) ->
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn upgrade_nixos(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Result<(), Error> {
|
||||
fn upgrade_nixos(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Result<()> {
|
||||
if let Some(sudo) = &sudo {
|
||||
run_type
|
||||
.execute(&sudo)
|
||||
@@ -388,7 +388,7 @@ fn upgrade_nixos(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Re
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_needrestart(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_needrestart(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {
|
||||
let sudo = require_option(sudo)?;
|
||||
let needrestart = require("needrestart")?;
|
||||
|
||||
@@ -400,7 +400,7 @@ pub fn run_needrestart(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(),
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_fwupdmgr(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_fwupdmgr(run_type: RunType) -> Result<()> {
|
||||
let fwupdmgr = require("fwupdmgr")?;
|
||||
|
||||
print_separator("Firmware upgrades");
|
||||
@@ -410,7 +410,7 @@ pub fn run_fwupdmgr(run_type: RunType) -> Result<(), Error> {
|
||||
|
||||
if let ExecutorExitStatus::Wet(e) = exit_status {
|
||||
if !(e.success() || e.code().map(|c| c == 2).unwrap_or(false)) {
|
||||
return Err(ErrorKind::ProcessFailed(e).into());
|
||||
return Err(TopgradeError::ProcessFailed(e).into());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ pub fn run_fwupdmgr(run_type: RunType) -> Result<(), Error> {
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn flatpak_update(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn flatpak_update(run_type: RunType) -> Result<()> {
|
||||
let flatpak = require("flatpak")?;
|
||||
print_separator("Flatpak User Packages");
|
||||
|
||||
@@ -433,12 +433,12 @@ pub fn flatpak_update(run_type: RunType) -> Result<(), Error> {
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_snap(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_snap(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {
|
||||
let sudo = require_option(sudo)?;
|
||||
let snap = require("snap")?;
|
||||
|
||||
if !PathBuf::from("/var/snapd.socket").exists() && !PathBuf::from("/run/snapd.socket").exists() {
|
||||
return Err(ErrorKind::SkipStep.into());
|
||||
return Err(SkipStep.into());
|
||||
}
|
||||
print_separator("snap");
|
||||
|
||||
@@ -446,7 +446,7 @@ pub fn run_snap(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error>
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_rpi_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_rpi_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {
|
||||
let sudo = require_option(sudo)?;
|
||||
let rpi_update = require("rpi-update")?;
|
||||
|
||||
@@ -456,7 +456,7 @@ pub fn run_rpi_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), E
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_pihole_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_pihole_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {
|
||||
let sudo = require_option(sudo)?;
|
||||
let pihole = require("pihole")?;
|
||||
|
||||
@@ -466,7 +466,7 @@ pub fn run_pihole_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_etc_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_etc_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {
|
||||
let sudo = require_option(sudo)?;
|
||||
let etc_update = require("etc-update")?;
|
||||
print_separator("etc-update");
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::error::Error;
|
||||
use crate::executor::RunType;
|
||||
use crate::terminal::print_separator;
|
||||
use anyhow::Result;
|
||||
|
||||
#[must_use]
|
||||
pub fn upgrade_macos(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn upgrade_macos(run_type: RunType) -> Result<()> {
|
||||
print_separator("App Store");
|
||||
|
||||
run_type
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
use crate::error::Error;
|
||||
#[cfg(target_os = "linux")]
|
||||
use crate::error::ErrorKind;
|
||||
use crate::error::SkipStep;
|
||||
use crate::executor::{CommandExt, RunType};
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::{require, PathExt};
|
||||
use anyhow::Result;
|
||||
use directories::BaseDirs;
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
pub fn run_fisher(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_fisher(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let fish = require("fish")?;
|
||||
base_dirs
|
||||
.home_dir()
|
||||
@@ -26,7 +26,7 @@ pub fn run_fisher(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error>
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_homebrew(cleanup: bool, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_homebrew(cleanup: bool, run_type: RunType) -> Result<()> {
|
||||
let brew = require("brew")?;
|
||||
print_separator("Brew");
|
||||
|
||||
@@ -52,7 +52,7 @@ pub fn run_homebrew(cleanup: bool, run_type: RunType) -> Result<(), Error> {
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn run_nix(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_nix(run_type: RunType) -> Result<()> {
|
||||
let nix = require("nix")?;
|
||||
let nix_channel = require("nix-channel")?;
|
||||
let nix_env = require("nix-env")?;
|
||||
@@ -65,7 +65,7 @@ pub fn run_nix(run_type: RunType) -> Result<(), Error> {
|
||||
|
||||
if let Ok(Distribution::NixOS) = Distribution::detect() {
|
||||
debug!("Nix on NixOS must be upgraded via 'nixos-rebuild switch', skipping.");
|
||||
return Err(ErrorKind::SkipStep.into());
|
||||
return Err(SkipStep.into());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,21 +74,21 @@ pub fn run_nix(run_type: RunType) -> Result<(), Error> {
|
||||
run_type.execute(&nix_env).arg("--upgrade").check_run()
|
||||
}
|
||||
|
||||
pub fn run_home_manager(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_home_manager(run_type: RunType) -> Result<()> {
|
||||
let home_manager = require("home-manager")?;
|
||||
|
||||
print_separator("home-manager");
|
||||
run_type.execute(&home_manager).arg("switch").check_run()
|
||||
}
|
||||
|
||||
pub fn run_pearl(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_pearl(run_type: RunType) -> Result<()> {
|
||||
let pearl = require("pearl")?;
|
||||
print_separator("pearl");
|
||||
|
||||
run_type.execute(&pearl).arg("update").check_run()
|
||||
}
|
||||
|
||||
pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Result<()> {
|
||||
let bash = require("bash")?;
|
||||
|
||||
let sdkman_init_path = env::var("SDKMAN_DIR")
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::error::SkipStep;
|
||||
use crate::executor::{CommandExt, RunType};
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::require;
|
||||
use anyhow::Result;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn run_chocolatey(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_chocolatey(run_type: RunType) -> Result<()> {
|
||||
let choco = require("choco")?;
|
||||
|
||||
print_separator("Chocolatey");
|
||||
run_type.execute(&choco).args(&["upgrade", "all"]).check_run()
|
||||
}
|
||||
|
||||
pub fn run_scoop(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_scoop(run_type: RunType) -> Result<()> {
|
||||
let scoop = require("scoop")?;
|
||||
|
||||
print_separator("Scoop");
|
||||
@@ -20,12 +21,12 @@ pub fn run_scoop(run_type: RunType) -> Result<(), Error> {
|
||||
run_type.execute(&scoop).args(&["update", "*"]).check_run()
|
||||
}
|
||||
|
||||
pub fn run_wsl_topgrade(run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_wsl_topgrade(run_type: RunType) -> Result<()> {
|
||||
let wsl = require("wsl")?;
|
||||
let topgrade = Command::new(&wsl)
|
||||
.args(&["bash", "-l", "which", "topgrade"])
|
||||
.check_output()
|
||||
.map_err(|_| ErrorKind::SkipStep)?;
|
||||
.map_err(|_| SkipStep)?;
|
||||
|
||||
run_type
|
||||
.execute(&wsl)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::error::Error;
|
||||
#[cfg(windows)]
|
||||
use crate::error::ErrorKind;
|
||||
use crate::error::SkipStep;
|
||||
use crate::executor::{CommandExt, RunType};
|
||||
use crate::terminal::{is_dumb, print_separator};
|
||||
use crate::utils::{require_option, which, PathExt};
|
||||
use anyhow::Result;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
@@ -53,7 +53,7 @@ impl Powershell {
|
||||
self.profile.as_ref()
|
||||
}
|
||||
|
||||
pub fn update_modules(&self, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn update_modules(&self, run_type: RunType) -> Result<()> {
|
||||
let powershell = require_option(self.path.as_ref())?;
|
||||
|
||||
print_separator("Powershell Modules Update");
|
||||
@@ -65,11 +65,11 @@ impl Powershell {
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn windows_update(&self, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn windows_update(&self, run_type: RunType) -> Result<()> {
|
||||
let powershell = require_option(self.path.as_ref())?;
|
||||
|
||||
if !Self::has_module(&powershell, "PSWindowsUpdate") {
|
||||
return Err(ErrorKind::SkipStep.into());
|
||||
return Err(SkipStep.into());
|
||||
}
|
||||
print_separator("Windows Update");
|
||||
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::executor::RunType;
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::{which, Check, PathExt};
|
||||
use anyhow::Result;
|
||||
use directories::BaseDirs;
|
||||
use failure::ResultExt;
|
||||
use std::env;
|
||||
use std::io;
|
||||
use std::os::unix::process::CommandExt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{exit, Command};
|
||||
|
||||
pub fn run_tpm(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_tpm(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let tpm = base_dirs
|
||||
.home_dir()
|
||||
.join(".tmux/plugins/tpm/bin/update_plugins")
|
||||
@@ -62,13 +61,11 @@ impl Tmux {
|
||||
.success())
|
||||
}
|
||||
|
||||
fn run_in_session(&self, command: &str) -> Result<(), Error> {
|
||||
fn run_in_session(&self, command: &str) -> Result<()> {
|
||||
self.build()
|
||||
.args(&["new-window", "-a", "-t", "topgrade:1", command])
|
||||
.spawn()
|
||||
.context(ErrorKind::ProcessExecution)?
|
||||
.wait()
|
||||
.context(ErrorKind::ProcessExecution)?
|
||||
.spawn()?
|
||||
.wait()?
|
||||
.check()?;
|
||||
|
||||
Ok(())
|
||||
@@ -107,7 +104,7 @@ pub fn run_in_tmux(args: &Option<String>) -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_remote_topgrade(hostname: &str, ssh: &Path, tmux_args: &Option<String>) -> Result<(), Error> {
|
||||
pub fn run_remote_topgrade(hostname: &str, ssh: &Path, tmux_args: &Option<String>) -> Result<()> {
|
||||
let command = format!(
|
||||
"{ssh} -t {hostname} env TOPGRADE_PREFIX={hostname} TOPGRADE_KEEP_END=1 topgrade",
|
||||
ssh = ssh.display(),
|
||||
@@ -117,9 +114,7 @@ pub fn run_remote_topgrade(hostname: &str, ssh: &Path, tmux_args: &Option<String
|
||||
.build()
|
||||
.args(&["new-window", "-a", "-t", "topgrade:1", &command])
|
||||
.env_remove("TMUX")
|
||||
.spawn()
|
||||
.context(ErrorKind::ProcessExecution)?
|
||||
.wait()
|
||||
.context(ErrorKind::ProcessExecution)?
|
||||
.spawn()?
|
||||
.wait()?
|
||||
.check()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use crate::error::{Error, ErrorKind};
|
||||
use crate::error::{SkipStep, TopgradeError};
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::executor::{CommandExt, ExecutorOutput, RunType};
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::{require, require_option, PathExt};
|
||||
@@ -74,7 +76,7 @@ fn upgrade(
|
||||
plugin_framework: PluginFramework,
|
||||
run_type: RunType,
|
||||
cleanup: bool,
|
||||
) -> Result<(), Error> {
|
||||
) -> Result<()> {
|
||||
let output = run_type
|
||||
.execute(&vim)
|
||||
.args(&["-N", "-u"])
|
||||
@@ -95,7 +97,7 @@ fn upgrade(
|
||||
if !status.success() {
|
||||
io::stdout().write(&output.stdout).ok();
|
||||
io::stderr().write(&output.stderr).ok();
|
||||
return Err(ErrorKind::ProcessFailed(status).into());
|
||||
return Err(TopgradeError::ProcessFailed(status).into());
|
||||
} else {
|
||||
println!("Plugins upgraded")
|
||||
}
|
||||
@@ -105,12 +107,12 @@ fn upgrade(
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn upgrade_vim(base_dirs: &BaseDirs, run_type: RunType, cleanup: bool) -> Result<(), Error> {
|
||||
pub fn upgrade_vim(base_dirs: &BaseDirs, run_type: RunType, cleanup: bool) -> Result<()> {
|
||||
let vim = require("vim")?;
|
||||
|
||||
let output = Command::new(&vim).arg("--version").check_output()?;
|
||||
if !output.starts_with("VIM") {
|
||||
return Err(ErrorKind::SkipStep.into());
|
||||
return Err(SkipStep.into());
|
||||
}
|
||||
|
||||
let vimrc = require_option(vimrc(&base_dirs))?;
|
||||
@@ -121,7 +123,7 @@ pub fn upgrade_vim(base_dirs: &BaseDirs, run_type: RunType, cleanup: bool) -> Re
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn upgrade_neovim(base_dirs: &BaseDirs, run_type: RunType, cleanup: bool) -> Result<(), Error> {
|
||||
pub fn upgrade_neovim(base_dirs: &BaseDirs, run_type: RunType, cleanup: bool) -> Result<()> {
|
||||
let nvim = require("nvim")?;
|
||||
let nvimrc = require_option(nvimrc(&base_dirs))?;
|
||||
let plugin_framework = require_option(PluginFramework::detect(&nvimrc))?;
|
||||
@@ -130,7 +132,7 @@ pub fn upgrade_neovim(base_dirs: &BaseDirs, run_type: RunType, cleanup: bool) ->
|
||||
upgrade(&nvim, &nvimrc, plugin_framework, run_type, cleanup)
|
||||
}
|
||||
|
||||
pub fn run_voom(_base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_voom(_base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let voom = require("voom")?;
|
||||
|
||||
print_separator("voom");
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use crate::error::Error;
|
||||
use crate::executor::RunType;
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::{require, PathExt};
|
||||
use anyhow::Result;
|
||||
use directories::BaseDirs;
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn run_zr(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_zr(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let zsh = require("zsh")?;
|
||||
|
||||
env::var("ZR_HOME")
|
||||
@@ -26,7 +26,7 @@ pub fn zshrc(base_dirs: &BaseDirs) -> PathBuf {
|
||||
.unwrap_or_else(|_| base_dirs.home_dir().join(".zshrc"))
|
||||
}
|
||||
|
||||
pub fn run_antigen(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_antigen(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let zsh = require("zsh")?;
|
||||
let zshrc = zshrc(base_dirs).require()?;
|
||||
env::var("ADOTDIR")
|
||||
@@ -40,7 +40,7 @@ pub fn run_antigen(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error>
|
||||
run_type.execute(zsh).args(&["-c", cmd.as_str()]).check_run()
|
||||
}
|
||||
|
||||
pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let zsh = require("zsh")?;
|
||||
let zshrc = zshrc(base_dirs).require()?;
|
||||
|
||||
@@ -55,7 +55,7 @@ pub fn run_zplug(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
run_type.execute(zsh).args(&["-c", cmd.as_str()]).check_run()
|
||||
}
|
||||
|
||||
pub fn run_zplugin(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_zplugin(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let zsh = require("zsh")?;
|
||||
let zshrc = zshrc(base_dirs).require()?;
|
||||
|
||||
@@ -73,7 +73,7 @@ pub fn run_zplugin(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error>
|
||||
run_type.execute(zsh).args(&["-c", cmd.as_str()]).check_run()
|
||||
}
|
||||
|
||||
pub fn run_oh_my_zsh(base_dirs: &BaseDirs, run_type: RunType) -> Result<(), Error> {
|
||||
pub fn run_oh_my_zsh(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
|
||||
let zsh = require("zsh")?;
|
||||
let zshrc = zshrc(base_dirs).require()?;
|
||||
base_dirs.home_dir().join(".oh-my-zsh").require()?;
|
||||
|
||||
Reference in New Issue
Block a user