Skip to content

Commit

Permalink
Merge pull request #2312 from LucianoBestia/shows_override_in_toolcha…
Browse files Browse the repository at this point in the history
…in_list

shows (override) in toolchain list
  • Loading branch information
kinnison authored May 30, 2020
2 parents 9a4ec54 + 9794c7d commit 4112620
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,13 @@ pub fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<()> {
Ok(())
}

fn print_toolchain_path(cfg: &Cfg, toolchain: &str, if_default: &str, verbose: bool) -> Result<()> {
fn print_toolchain_path(
cfg: &Cfg,
toolchain: &str,
if_default: &str,
if_override: &str,
verbose: bool,
) -> Result<()> {
let toolchain_path = {
let mut t_path = cfg.toolchains_dir.clone();
t_path.push(&toolchain);
Expand All @@ -438,27 +444,43 @@ fn print_toolchain_path(cfg: &Cfg, toolchain: &str, if_default: &str, verbose: b
} else {
String::new()
};
println!("{}{}{}", &toolchain, if_default, toolchain_path);
println!(
"{}{}{}{}",
&toolchain, if_default, if_override, toolchain_path
);
Ok(())
}

pub fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<()> {
let toolchains = cfg.list_toolchains()?;
if toolchains.is_empty() {
println!("no installed toolchains");
} else if let Ok(Some(def_toolchain)) = cfg.find_default() {
} else {
let def_toolchain_name = if let Ok(Some(def_toolchain)) = cfg.find_default() {
def_toolchain.name().to_string()
} else {
String::new()
};
let cwd = utils::current_dir()?;
let ovr_toolchain_name = if let Ok(Some((ovr_toolchain, _reason))) = cfg.find_override(&cwd)
{
ovr_toolchain.name().to_string()
} else {
String::new()
};
for toolchain in toolchains {
let if_default = if def_toolchain.name() == &*toolchain {
let if_default = if def_toolchain_name == &*toolchain {
" (default)"
} else {
""
};
print_toolchain_path(cfg, &toolchain, if_default, verbose)
.expect("Failed to list toolchains' directories");
}
} else {
for toolchain in toolchains {
print_toolchain_path(cfg, &toolchain, "", verbose)
let if_override = if ovr_toolchain_name == &*toolchain {
" (override)"
} else {
""
};

print_toolchain_path(cfg, &toolchain, if_default, if_override, verbose)
.expect("Failed to list toolchains' directories");
}
}
Expand Down
33 changes: 33 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,39 @@ fn list_default_toolchain() {
});
}

#[test]
fn list_override_toolchain() {
setup(&|config| {
expect_ok(config, &["rustup", "override", "set", "nightly"]);
expect_ok_ex(
config,
&["rustup", "toolchain", "list"],
for_host!(
r"nightly-{0} (override)
"
),
r"",
);
});
}

#[test]
fn list_default_and_override_toolchain() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok(config, &["rustup", "override", "set", "nightly"]);
expect_ok_ex(
config,
&["rustup", "toolchain", "list"],
for_host!(
r"nightly-{0} (default) (override)
"
),
r"",
);
});
}

#[test]
#[ignore = "FIXME: Windows shows UNC paths"]
fn show_toolchain_override() {
Expand Down

0 comments on commit 4112620

Please sign in to comment.