Skip to content

Commit d3d1d98

Browse files
committed
feat(rustup-mode)!: add ensure_active_toolchain flag to update()
1 parent c0cf0ab commit d3d1d98

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/cli/rustup_mode.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
584584

585585
match subcmd {
586586
RustupSubcmd::DumpTestament => common::dump_testament(process),
587-
RustupSubcmd::Install { opts } => update(cfg, opts).await,
587+
RustupSubcmd::Install { opts } => update(cfg, opts, false).await,
588588
RustupSubcmd::Uninstall { opts } => toolchain_remove(cfg, opts),
589589
RustupSubcmd::Show { verbose, subcmd } => handle_epipe(match subcmd {
590590
None => show(cfg, verbose),
@@ -610,11 +610,12 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
610610
force_non_host,
611611
..UpdateOpts::default()
612612
},
613+
false,
613614
)
614615
.await
615616
}
616617
RustupSubcmd::Toolchain { subcmd } => match subcmd {
617-
ToolchainSubcmd::Install { opts } => update(cfg, opts).await,
618+
ToolchainSubcmd::Install { opts } => update(cfg, opts, false).await,
618619
ToolchainSubcmd::List { verbose, quiet } => {
619620
handle_epipe(common::list_toolchains(cfg, verbose, quiet))
620621
}
@@ -791,7 +792,11 @@ async fn check_updates(cfg: &Cfg<'_>) -> Result<utils::ExitCode> {
791792
Ok(utils::ExitCode(0))
792793
}
793794

794-
async fn update(cfg: &mut Cfg<'_>, opts: UpdateOpts) -> Result<utils::ExitCode> {
795+
async fn update(
796+
cfg: &mut Cfg<'_>,
797+
opts: UpdateOpts,
798+
ensure_active_toolchain: bool,
799+
) -> Result<utils::ExitCode> {
795800
let mut exit_code = utils::ExitCode(0);
796801

797802
common::warn_if_host_is_emulated(cfg.process);
@@ -861,6 +866,13 @@ async fn update(cfg: &mut Cfg<'_>, opts: UpdateOpts) -> Result<utils::ExitCode>
861866
if self_update {
862867
exit_code &= common::self_update(|| Ok(()), cfg.process).await?;
863868
}
869+
} else if ensure_active_toolchain {
870+
let (toolchain, reason) = cfg.find_or_install_active_toolchain(true).await?;
871+
info!(
872+
"the active toolchain `{}` has been installed",
873+
toolchain.name()
874+
);
875+
info!("it's active because: {reason}");
864876
} else {
865877
exit_code &= common::update_all_channels(cfg, self_update, opts.force).await?;
866878
info!("cleaning up downloads & tmp directories");

src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ impl<'a> Cfg<'a> {
737737
}
738738

739739
#[tracing::instrument(level = "trace", skip_all)]
740-
async fn find_or_install_active_toolchain(
740+
pub(crate) async fn find_or_install_active_toolchain(
741741
&'a self,
742742
verbose: bool,
743743
) -> Result<(Toolchain<'a>, ActiveReason)> {

0 commit comments

Comments
 (0)