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
59 changes: 34 additions & 25 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use std::{
};

use anstream::ColorChoice;
use anstyle::{AnsiColor, Style};
use anyhow::{Context, Error, Result, anyhow};
use clap::{Args, CommandFactory, Parser, Subcommand, ValueEnum, builder::PossibleValue};
use clap_cargo::style::{CONTEXT, HEADER};
use clap_complete::Shell;
use console::style;
use futures_util::stream::StreamExt;
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use itertools::Itertools;
Expand Down Expand Up @@ -819,6 +819,30 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<ExitCode> {
Some(_) | None => channels_len,
};

let bold = if use_colors {
Style::new().bold()
} else {
Style::new()
};

let error = if use_colors {
AnsiColor::Red.on_default().bold()
} else {
Style::new()
};

let good = if use_colors {
AnsiColor::Green.on_default().bold()
} else {
Style::new()
};

let warn = if use_colors {
AnsiColor::Yellow.on_default().bold()
} else {
Style::new()
};

// Ensure that `.buffered()` is never called with 0 as this will cause a hang.
// See: https://github.com/rust-lang/futures-rs/pull/1194#discussion_r209501774
if channels_len > 0 {
Expand All @@ -842,40 +866,25 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<ExitCode> {
let dist_version = distributable.show_dist_version().await?;
let mut update_a = false;

let mut styled_name = style(format!("{name} - "));
if use_colors {
styled_name = styled_name.bold();
}
let styled_name = format!("{bold}{name} - {bold:#}");
let message = match (current_version, dist_version) {
(None, None) => {
let mut m = style("Cannot identify installed or update versions");
if use_colors {
m = m.red().bold();
}
format!("{styled_name}{m}")
let m = "Cannot identify installed or update versions";
format!("{styled_name}{error}{m}{error:#}")
}
(Some(cv), None) => {
let mut m = style("Up to date");
if use_colors {
m = m.green().bold();
}
format!("{styled_name}{m} : {cv}")
let m = "Up to date";
format!("{styled_name}{good}{m}{good:#} : {cv}")
}
(Some(cv), Some(dv)) => {
let mut m = style("Update available");
if use_colors {
m = m.yellow().bold();
}
let m = "Update available";
update_a = true;
format!("{styled_name}{m} : {cv} -> {dv}")
format!("{styled_name}{warn}{m}{warn:#} : {cv} -> {dv}")
}
(None, Some(dv)) => {
let mut m = style("Update available");
if use_colors {
m = m.yellow().bold();
}
let m = "Update available";
update_a = true;
format!("{styled_name}{m} : (Unknown version) -> {dv}")
format!("{styled_name}{warn}{m}{warn:#} : (Unknown version) -> {dv}")
}
};
pb.set_style(ProgressStyle::with_template(message.as_str()).unwrap());
Expand Down
44 changes: 44 additions & 0 deletions tests/suite/cli_rustup_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,50 @@ fn rustup_only_options() {
test_error("rustup_only_options", &["-q"]);
}

#[tokio::test]
async fn rustup_check_updates_none() {
let name = "rustup_check_updates_none";
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "toolchain", "add", "stable", "beta", "nightly"])
.await
.is_ok();
cx.config
.expect_with_env(["rustup", "check"], [("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_err();
}

#[tokio::test]
async fn rustup_check_updates_some() {
let name = "rustup_check_updates_some";
let mut cx = CliTestContext::new(Scenario::None).await;

{
let cx = cx.with_dist_dir(Scenario::ArchivesV2_2015_01_01);
cx.config
.expect(["rustup", "toolchain", "add", "stable", "beta", "nightly"])
.await
.is_ok();
}

let cx = cx.with_dist_dir(Scenario::SimpleV2);
cx.config
.expect_with_env(["rustup", "check"], [("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_check_cmd_help_flag() {
test_help("rustup_check_cmd_help_flag", &["check", "--help"]);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading