Skip to content

Commit

Permalink
Do not allow to uninstall the latest toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
crodas committed Feb 22, 2024
1 parent f944f62 commit 8b43be8
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/ops/fuelup_toolchain/uninstall.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use anyhow::{bail, Result};
use std::str::FromStr;
use tracing::{error, info};

use crate::{
commands::toolchain::UninstallCommand,
config::Config,
fmt::{println_error, println_warn},
ops::fuelup_default,
toolchain::{DistToolchainDescription, Toolchain},
};
Expand All @@ -20,13 +20,17 @@ pub fn uninstall(command: UninstallCommand) -> Result<()> {
};

if !toolchain.exists() {
info!("toolchain '{}' does not exist", &toolchain.name);
println_warn(format!("Toolchain '{}' does not exist", &toolchain.name));
return Ok(());
}

if config.list_toolchains()?.len() == 1 {
bail!("Cannot uninstall the last toolchain");
}

match toolchain.uninstall_self() {
Ok(_) => {
info!("toolchain '{}' uninstalled", &toolchain.name);
println!("Toolchain '{}' uninstalled", &toolchain.name);
let active_toolchain = Toolchain::from_settings()?;
if active_toolchain.name == toolchain.name {
for toolchain in config.list_toolchains()? {
Expand All @@ -35,16 +39,17 @@ pub fn uninstall(command: UninstallCommand) -> Result<()> {
}
}

error!(
println_error(format!(
"{}\r\t{}",
"Could not set default toolchain after uninstallation of currently used toolchain",
"Please run `fuelup default <toolchain>` to manually switch your current toolchain."
)
));
}
}
Err(e) => {
bail!("Failed to uninstall toolchain '{}': {}", &toolchain.name, e)
}
Err(e) => println_error(format!(
"Failed to uninstall toolchain '{}': {}",
&toolchain.name, e
)),
};

Ok(())
Expand Down

0 comments on commit 8b43be8

Please sign in to comment.