Skip to content
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: 9 additions & 11 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{cmp, env};

use anstyle::Style;
use anyhow::{Context, Result, anyhow};
use clap_cargo::style::{ERROR, UPDATE_ADDED, UPDATE_UNCHANGED, UPDATE_UPGRADED};
use clap_cargo::style::{CONTEXT, ERROR, UPDATE_ADDED, UPDATE_UNCHANGED, UPDATE_UPGRADED};
use git_testament::{git_testament, render_testament};
use tracing::{error, info, warn};
use tracing_subscriber::{EnvFilter, Registry, reload::Handle};
Expand Down Expand Up @@ -307,6 +307,13 @@ pub(crate) async fn list_toolchains(
return Ok(());
}

let status_str = match (is_default, is_active) {
(true, true) => " (active, default)",
(true, false) => " (default)",
(false, true) => " (active)",
(false, false) => "",
};

let toolchain_path = cfg.toolchains_dir.join(toolchain);
let toolchain_meta = fs::symlink_metadata(&toolchain_path)?;
let toolchain_path = if verbose {
Expand All @@ -318,19 +325,10 @@ pub(crate) async fn list_toolchains(
} else {
String::new()
};
let status_str = match (is_default, is_active) {
(true, true) => " (active, default)",
(true, false) => " (default)",
(false, true) => " (active)",
(false, false) => "",
};

writeln!(
cfg.process.stdout().lock(),
"{}{}{}",
&toolchain,
status_str,
toolchain_path
"{toolchain}{CONTEXT}{status_str}{CONTEXT:#}{toolchain_path}",
)?;
Ok(())
}
Expand Down
26 changes: 26 additions & 0 deletions tests/suite/cli_rustup_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,32 @@ fn rustup_toolchain_cmd_link_cmd_help_flag() {
);
}

#[tokio::test]
async fn rustup_toolchain_list() {
let name = "rustup_toolchain_list";
let cx = CliTestContext::new(Scenario::ArchivesV2).await;
cx.config
.expect(["rustup", "update", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustup", "update", "beta-2015-01-01"])
.await
.is_ok();
cx.config
.expect_with_env(
["rustup", "toolchain", "list"],
[("RUSTUP_TERM_COLOR", "always")],
)
.await
.with_stdout(Data::read_from(
Path::new(&format!("tests/suite/cli_rustup_ui/{name}.stdout.term.svg")),
None,
))
.with_stderr("")
.is_ok();
}

#[test]
fn rustup_toolchain_cmd_list_cmd_help_flag() {
test_help(
Expand Down
29 changes: 29 additions & 0 deletions tests/suite/cli_rustup_ui/rustup_toolchain_list.stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.