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