Migrate from failure to anyhow/thiserror (#273)
This commit is contained in:
committed by
GitHub
parent
1ea9b91e11
commit
ba516aa1dd
@@ -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))]
|
||||
|
||||
Reference in New Issue
Block a user