mirror of
https://github.com/esp-rs/espup.git
synced 2025-10-02 23:25:16 +00:00
fix: 🐛 Return miette::Report instead of Error
This commit is contained in:
parent
d871f23e44
commit
c7535d574f
15
src/main.rs
15
src/main.rs
@ -24,7 +24,7 @@ use espup::{
|
|||||||
update::check_for_update,
|
update::check_for_update,
|
||||||
};
|
};
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
use miette::Result;
|
use miette::{IntoDiagnostic, Result};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
fs::{remove_dir_all, remove_file, File},
|
fs::{remove_dir_all, remove_file, File},
|
||||||
@ -128,7 +128,7 @@ pub struct UninstallOpts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Installs the Rust for ESP chips environment
|
/// Installs the Rust for ESP chips environment
|
||||||
fn install(args: InstallOpts) -> Result<(), Error> {
|
fn install(args: InstallOpts) -> Result<()> {
|
||||||
initialize_logger(&args.log_level);
|
initialize_logger(&args.log_level);
|
||||||
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
||||||
info!("{} Installing esp-rs", emoji::DISC);
|
info!("{} Installing esp-rs", emoji::DISC);
|
||||||
@ -244,7 +244,7 @@ fn install(args: InstallOpts) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Uninstalls the Rust for ESP chips environment
|
/// Uninstalls the Rust for ESP chips environment
|
||||||
fn uninstall(args: UninstallOpts) -> Result<(), Error> {
|
fn uninstall(args: UninstallOpts) -> Result<()> {
|
||||||
initialize_logger(&args.log_level);
|
initialize_logger(&args.log_level);
|
||||||
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
@ -270,6 +270,7 @@ fn uninstall(args: UninstallOpts) -> Result<(), Error> {
|
|||||||
config.llvm_path = None;
|
config.llvm_path = None;
|
||||||
config.save()?;
|
config.save()?;
|
||||||
remove_dir_all(&llvm_path)
|
remove_dir_all(&llvm_path)
|
||||||
|
.into_diagnostic()
|
||||||
.map_err(|_| Error::FailedToRemoveDirectory(llvm_path.display().to_string()))?;
|
.map_err(|_| Error::FailedToRemoveDirectory(llvm_path.display().to_string()))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +309,9 @@ fn uninstall(args: UninstallOpts) -> Result<(), Error> {
|
|||||||
updated_extra_crates.remove(extra_crate);
|
updated_extra_crates.remove(extra_crate);
|
||||||
config.extra_crates = Some(updated_extra_crates.clone());
|
config.extra_crates = Some(updated_extra_crates.clone());
|
||||||
config.save()?;
|
config.save()?;
|
||||||
cmd!("cargo", "uninstall", extra_crate).run()?;
|
cmd!("cargo", "uninstall", extra_crate)
|
||||||
|
.run()
|
||||||
|
.into_diagnostic()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,7 +334,7 @@ fn uninstall(args: UninstallOpts) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Updates Xtensa Rust toolchain.
|
/// Updates Xtensa Rust toolchain.
|
||||||
fn update(args: UpdateOpts) -> Result<(), Error> {
|
fn update(args: UpdateOpts) -> Result<()> {
|
||||||
initialize_logger(&args.log_level);
|
initialize_logger(&args.log_level);
|
||||||
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
@ -376,7 +379,7 @@ fn update(args: UpdateOpts) -> Result<(), Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Error> {
|
fn main() -> Result<()> {
|
||||||
match Cli::parse().subcommand {
|
match Cli::parse().subcommand {
|
||||||
SubCommand::Install(args) => install(*args),
|
SubCommand::Install(args) => install(*args),
|
||||||
SubCommand::Update(args) => update(args),
|
SubCommand::Update(args) => update(args),
|
||||||
|
@ -8,7 +8,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use embuild::cmd;
|
use embuild::cmd;
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
use miette::Result;
|
use miette::{IntoDiagnostic, Result};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use reqwest::header;
|
use reqwest::header;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -188,11 +188,13 @@ impl XtensaRust {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the Xtensa Rust toolchain.
|
/// Removes the Xtensa Rust toolchain.
|
||||||
pub fn uninstall(&self) -> Result<(), Error> {
|
pub fn uninstall(&self) -> Result<()> {
|
||||||
info!("{} Uninstalling Xtensa Rust toolchain", emoji::WRENCH);
|
info!("{} Uninstalling Xtensa Rust toolchain", emoji::WRENCH);
|
||||||
remove_dir_all(&self.toolchain_destination).map_err(|_| {
|
remove_dir_all(&self.toolchain_destination)
|
||||||
Error::FailedToRemoveDirectory(self.toolchain_destination.display().to_string())
|
.into_diagnostic()
|
||||||
})?;
|
.map_err(|_| {
|
||||||
|
Error::FailedToRemoveDirectory(self.toolchain_destination.display().to_string())
|
||||||
|
})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user