Skip to content

Commit c9cf94f

Browse files
committed
Use terse output for rustup show active-toolchain
1 parent 5f3b272 commit c9cf94f

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

src/cli/rustup_mode.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -1085,18 +1085,26 @@ fn show_active_toolchain(cfg: &Cfg<'_>, verbose: bool) -> Result<utils::ExitCode
10851085
match cfg.find_active_toolchain()? {
10861086
Some((toolchain_name, reason)) => {
10871087
let toolchain = Toolchain::with_reason(cfg, toolchain_name.clone(), &reason)?;
1088-
writeln!(
1089-
cfg.process.stdout().lock(),
1090-
"{}\nactive because: {}",
1091-
toolchain.name(),
1092-
reason
1093-
)?;
10941088
if verbose {
10951089
writeln!(
10961090
cfg.process.stdout().lock(),
1097-
"compiler: {}\npath: {}",
1091+
"{}\nactive because: {}\ncompiler: {}\npath: {}",
1092+
toolchain.name(),
1093+
reason,
10981094
toolchain.rustc_version(),
1099-
toolchain.path().display(),
1095+
toolchain.path().display()
1096+
)?;
1097+
} else {
1098+
let reason: &dyn fmt::Display = if matches!(reason, ActiveReason::Default) {
1099+
&"default"
1100+
} else {
1101+
&reason
1102+
};
1103+
writeln!(
1104+
cfg.process.stdout().lock(),
1105+
"{} ({})",
1106+
toolchain.name(),
1107+
reason
11001108
)?;
11011109
}
11021110
}

tests/suite/cli_rustup.rs

+31-2
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ async fn show_active_toolchain() {
11691169
cx.config
11701170
.expect_ok_ex(
11711171
&["rustup", "show", "active-toolchain"],
1172-
for_host!("nightly-{0}\nactive because: it's the default toolchain\n"),
1172+
for_host!("nightly-{0} (default)\n"),
11731173
r"",
11741174
)
11751175
.await;
@@ -1260,7 +1260,36 @@ async fn show_active_toolchain_with_override() {
12601260
cx.config
12611261
.expect_stdout_ok(
12621262
&["rustup", "show", "active-toolchain"],
1263-
for_host!("stable-{0}\nactive because: directory override for"),
1263+
for_host!("stable-{0}"),
1264+
)
1265+
.await;
1266+
}
1267+
1268+
#[tokio::test]
1269+
async fn show_active_toolchain_with_override_verbose() {
1270+
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
1271+
cx.config.expect_ok(&["rustup", "default", "stable"]).await;
1272+
cx.config.expect_ok(&["rustup", "default", "nightly"]).await;
1273+
cx.config
1274+
.expect_ok(&["rustup", "override", "set", "stable"])
1275+
.await;
1276+
cx.config
1277+
.expect_ok_ex(
1278+
&["rustup", "show", "active-toolchain", "--verbose"],
1279+
for_host!(
1280+
r"stable-{0}
1281+
active because: directory override for '{1}'
1282+
compiler: 1.1.0 (hash-stable-1.1.0)
1283+
path: {2}
1284+
",
1285+
cx.config.current_dir().display(),
1286+
cx.config
1287+
.rustupdir
1288+
.join("toolchains")
1289+
.join(for_host!("stable-{0}"))
1290+
.display(),
1291+
),
1292+
r"",
12641293
)
12651294
.await;
12661295
}

0 commit comments

Comments
 (0)