Skip to content

Commit

Permalink
refactor(config): simplify find_or_install_active_toolchain()
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Aug 9, 2024
1 parent 108138d commit f61d03d
Showing 1 changed file with 25 additions and 38 deletions.
63 changes: 25 additions & 38 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,45 +744,32 @@ impl<'a> Cfg<'a> {
&self,
verbose: bool,
) -> Result<(LocalToolchainName, ActiveReason)> {
match self.find_override_config()? {
Some((override_config, reason)) => match override_config {
OverrideCfg::PathBased(path_based_name) => {
let toolchain = Toolchain::with_reason(self, path_based_name.into(), &reason)?;
Ok((toolchain.name().clone(), reason))
}
OverrideCfg::Custom(custom_name) => {
let toolchain = Toolchain::with_reason(self, custom_name.into(), &reason)?;
Ok((toolchain.name().clone(), reason))
}
OverrideCfg::Official {
if let Some((override_config, reason)) = self.find_override_config()? {
if let OverrideCfg::Official {
toolchain,
components,
targets,
profile,
} = &override_config
{
self.ensure_installed(
toolchain,
components,
targets,
profile,
} => {
let toolchain = self
.ensure_installed(&toolchain, components, targets, profile, verbose)
.await?
.1;
Ok((toolchain.name().clone(), reason))
}
},
None => match self.get_default()? {
None => Err(no_toolchain_error(self.process)),
Some(ToolchainName::Custom(custom_name)) => {
let reason = ActiveReason::Default;
let toolchain = Toolchain::with_reason(self, custom_name.into(), &reason)?;
Ok((toolchain.name().clone(), reason))
}
Some(ToolchainName::Official(toolchain_desc)) => {
let reason = ActiveReason::Default;
let toolchain = self
.ensure_installed(&toolchain_desc, vec![], vec![], None, verbose)
.await?
.1;
Ok((toolchain.name().clone(), reason))
}
},
components.clone(),
targets.clone(),
*profile,
verbose,
)
.await?;
}
Ok((override_config.into_local_toolchain_name(), reason))
} else if let Some(toolchain) = self.get_default()? {
if let ToolchainName::Official(desc) = &toolchain {
self.ensure_installed(desc, vec![], vec![], None, verbose)
.await?;
}
Ok((toolchain.into(), ActiveReason::Default))
} else {
Err(no_toolchain_error(self.process))
}
}

Expand Down

0 comments on commit f61d03d

Please sign in to comment.