Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring output of rustup show active-toolchain and rustup default into line with rest of rustup #1654

Merged
merged 4 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,17 +592,7 @@ fn default_(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
common::show_channel_update(cfg, toolchain.name(), Ok(status))?;
}
} else {
let installed_toolchains = cfg.list_toolchains()?;
if installed_toolchains.len() > 0 {
let default_toolchain = cfg.get_default()?;
if default_toolchain != "" {
let mut t = term2::stdout();
let _ = t.attr(term2::Attr::Bold);
let _ = write!(t, "Default toolchain: ");
let _ = t.reset();
println!("{}", default_toolchain);
}
}
println!("{} (default)", cfg.get_default()?);
}

Ok(())
Expand Down Expand Up @@ -793,8 +783,12 @@ fn show(cfg: &Cfg) -> Result<()> {

fn show_active_toolchain(cfg: &Cfg) -> Result<()> {
let ref cwd = utils::current_dir()?;
if let Some((toolchain, _)) = cfg.find_override_toolchain_or_default(cwd)? {
writeln!(term2::stdout(), "{}", toolchain.name())?
if let Some((toolchain, reason)) = cfg.find_override_toolchain_or_default(cwd)? {
if reason.is_some() {
println!("{} ({})", toolchain.name(), reason.unwrap());
} else {
println!("{} (default)", toolchain.name());
}
}
Ok(())
}
Expand Down
16 changes: 15 additions & 1 deletion tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,14 +861,28 @@ fn show_active_toolchain() {
config,
&["rustup", "show", "active-toolchain"],
for_host!(
r"nightly-{0}
r"nightly-{0} (default)
"
),
r"",
);
});
}

#[test]
fn show_active_toolchain_with_override() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "stable"]);
expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok(config, &["rustup", "override", "set", "stable"]);
expect_stdout_ok(
config,
&["rustup", "show", "active-toolchain"],
for_host!("stable-{0} (directory override for"),
);
});
}

#[test]
fn show_active_toolchain_none() {
setup(&|config| {
Expand Down