Skip to content

Commit b33079d

Browse files
committed
cli: extract display_version() from rustup main()
1 parent aceb09b commit b33079d

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/cli/rustup_mode.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -583,21 +583,9 @@ pub async fn main(
583583
}
584584
Err(err) if err.kind() == DisplayVersion => {
585585
write!(process.stdout().lock(), "{err}")?;
586-
info!("This is the version for the rustup toolchain manager, not the rustc compiler.");
587-
let mut cfg = Cfg::from_env(current_dir, true, process)?;
588-
cfg.toolchain_override = cfg
589-
.process
590-
.args()
591-
.find_map(|arg| arg.strip_prefix('+').map(ResolvableToolchainName::try_from))
592-
.transpose()?;
593-
match cfg.active_rustc_version().await {
594-
Ok(Some(version)) => info!("The currently active `rustc` version is `{version}`"),
595-
Ok(None) => info!("No `rustc` is currently active"),
596-
Err(err) => trace!("Failed to display the current `rustc` version: {err}"),
597-
}
586+
display_version(current_dir, process).await?;
598587
return Ok(ExitCode(0));
599588
}
600-
601589
Err(err) => {
602590
if [
603591
InvalidSubcommand,
@@ -1891,3 +1879,21 @@ fn output_completion_script(
18911879

18921880
Ok(ExitCode(0))
18931881
}
1882+
1883+
async fn display_version(current_dir: PathBuf, process: &Process) -> Result<()> {
1884+
info!("This is the version for the rustup toolchain manager, not the rustc compiler.");
1885+
let mut cfg = Cfg::from_env(current_dir, true, process)?;
1886+
cfg.toolchain_override = cfg
1887+
.process
1888+
.args()
1889+
.find_map(|arg| arg.strip_prefix('+').map(ResolvableToolchainName::try_from))
1890+
.transpose()?;
1891+
1892+
match cfg.active_rustc_version().await {
1893+
Ok(Some(version)) => info!("The currently active `rustc` version is `{version}`"),
1894+
Ok(None) => info!("No `rustc` is currently active"),
1895+
Err(err) => trace!("Failed to display the current `rustc` version: {err}"),
1896+
}
1897+
1898+
Ok(())
1899+
}

tests/suite/cli_misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ info: This is the version for the rustup toolchain manager, not the rustc compil
4141
.await
4242
.with_stderr(snapbox::str![[r#"
4343
...
44-
info: The currently active `rustc` version is `1.3.0 (hash-nightly-2)`
44+
info: the currently active `rustc` version is `1.3.0 (hash-nightly-2)`
4545
...
4646
"#]])
4747
.is_ok();

0 commit comments

Comments
 (0)