Skip to content

Commit c39e791

Browse files
authored
Merge pull request #1654 from lazorgator/print-default-redux
Bring output of `rustup show active-toolchain` and `rustup default` into line with rest of rustup
2 parents 6b89dff + 3e9e797 commit c39e791

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/rustup-cli/rustup_mode.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -583,17 +583,7 @@ fn default_(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
583583
common::show_channel_update(cfg, toolchain.name(), Ok(status))?;
584584
}
585585
} else {
586-
let installed_toolchains = cfg.list_toolchains()?;
587-
if installed_toolchains.len() > 0 {
588-
let default_toolchain = cfg.get_default()?;
589-
if default_toolchain != "" {
590-
let mut t = term2::stdout();
591-
let _ = t.attr(term2::Attr::Bold);
592-
let _ = write!(t, "Default toolchain: ");
593-
let _ = t.reset();
594-
println!("{}", default_toolchain);
595-
}
596-
}
586+
println!("{} (default)", cfg.get_default()?);
597587
}
598588

599589
Ok(())
@@ -788,8 +778,12 @@ fn show(cfg: &Cfg) -> Result<()> {
788778

789779
fn show_active_toolchain(cfg: &Cfg) -> Result<()> {
790780
let ref cwd = utils::current_dir()?;
791-
if let Some((toolchain, _)) = cfg.find_override_toolchain_or_default(cwd)? {
792-
writeln!(term2::stdout(), "{}", toolchain.name())?
781+
if let Some((toolchain, reason)) = cfg.find_override_toolchain_or_default(cwd)? {
782+
if reason.is_some() {
783+
println!("{} ({})", toolchain.name(), reason.unwrap());
784+
} else {
785+
println!("{} (default)", toolchain.name());
786+
}
793787
}
794788
Ok(())
795789
}

tests/cli-rustup.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,14 +861,28 @@ fn show_active_toolchain() {
861861
config,
862862
&["rustup", "show", "active-toolchain"],
863863
for_host!(
864-
r"nightly-{0}
864+
r"nightly-{0} (default)
865865
"
866866
),
867867
r"",
868868
);
869869
});
870870
}
871871

872+
#[test]
873+
fn show_active_toolchain_with_override() {
874+
setup(&|config| {
875+
expect_ok(config, &["rustup", "default", "stable"]);
876+
expect_ok(config, &["rustup", "default", "nightly"]);
877+
expect_ok(config, &["rustup", "override", "set", "stable"]);
878+
expect_stdout_ok(
879+
config,
880+
&["rustup", "show", "active-toolchain"],
881+
for_host!("stable-{0} (directory override for"),
882+
);
883+
});
884+
}
885+
872886
#[test]
873887
fn show_active_toolchain_none() {
874888
setup(&|config| {

0 commit comments

Comments
 (0)