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
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ anyhow = "1.0.69"
cfg-if = "1.0"
chrono = { version = "0.4", default-features = false, features = ["std"] }
clap = { version = "4", features = ["derive", "wrap_help", "string"] }
clap-cargo = "0.18.2"
clap-cargo = "0.18.3"
clap_complete = "4"
console = "0.16"
curl = { version = "0.4.44", optional = true }
Expand Down
15 changes: 6 additions & 9 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use std::{
};

use anstream::ColorChoice;
use anstyle::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;
Expand Down Expand Up @@ -1081,15 +1081,13 @@ async fn which(
async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<ExitCode> {
common::warn_if_host_is_emulated(cfg.process);

let bold = Style::new().bold();

// Print host triple
{
let t = cfg.process.stdout();
let mut t = t.lock();
writeln!(
t,
"{bold}Default host: {bold:#}{}",
"{HEADER}Default host: {HEADER:#}{}",
cfg.get_default_host_triple()?
)?;
}
Expand All @@ -1100,7 +1098,7 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<ExitCode> {
let mut t = t.lock();
writeln!(
t,
"{bold}rustup home: {bold:#}{}",
"{HEADER}rustup home: {HEADER:#}{}",
cfg.rustup_dir.display()
)?;
writeln!(t)?;
Expand Down Expand Up @@ -1155,7 +1153,7 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<ExitCode> {
(false, false) => "",
};

writeln!(t.lock(), "{toolchain_name}{status_str}")?;
writeln!(t.lock(), "{toolchain_name}{CONTEXT}{status_str}{CONTEXT:#}")?;

if verbose {
let toolchain = Toolchain::new(cfg, toolchain_name.into())?;
Expand Down Expand Up @@ -1208,11 +1206,10 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<ExitCode> {
}

fn print_header(t: &mut ColorableTerminal, text: &str) -> Result<(), Error> {
let bold = Style::new().bold();
let divider = "-".repeat(text.len());
let mut term_lock = t.lock();
writeln!(term_lock, "{bold}{text}{bold:#}")?;
writeln!(term_lock, "{bold}{divider}{bold:#}")?;
writeln!(term_lock, "{HEADER}{text}{HEADER:#}")?;
writeln!(term_lock, "{HEADER}{divider}{HEADER:#}")?;
Ok(())
}

Expand Down
22 changes: 18 additions & 4 deletions src/process/terminal_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ impl ColorableTerminal {
StreamSelector::Stdout => TerminalInner::Stdout(AutoStream::new(io::stdout(), choice)),
StreamSelector::Stderr => TerminalInner::Stderr(AutoStream::new(io::stderr(), choice)),
#[cfg(feature = "test")]
StreamSelector::TestWriter(w) => TerminalInner::TestWriter(w),
StreamSelector::TestWriter(w) if choice == ColorChoice::Always => {
TerminalInner::StyledTestWriter(w)
}
#[cfg(feature = "test")]
StreamSelector::TestWriter(w) => TerminalInner::TestWriter(StripStream::new(w)),
};
let width = process
.var("RUSTUP_TERM_WIDTH")
Expand All @@ -84,9 +88,13 @@ impl ColorableTerminal {
self.color_choice,
)),
#[cfg(feature = "test")]
TerminalInner::TestWriter(w) => {
ColorableTerminalLocked::TestWriter(StripStream::new(Box::new(w.clone())))
TerminalInner::StyledTestWriter(w) => {
ColorableTerminalLocked::StyledTestWriter(Box::new(w.clone()))
}
#[cfg(feature = "test")]
TerminalInner::TestWriter(w) => ColorableTerminalLocked::TestWriter(StripStream::new(
Box::new(w.as_inner().clone()),
)),
}
}

Expand Down Expand Up @@ -189,6 +197,8 @@ pub enum ColorableTerminalLocked {
Stdout(AutoStream<io::StdoutLock<'static>>),
Stderr(AutoStream<io::StderrLock<'static>>),
#[cfg(feature = "test")]
StyledTestWriter(Box<dyn Write>),
#[cfg(feature = "test")]
TestWriter(StripStream<Box<dyn Write>>),
}

Expand All @@ -198,6 +208,8 @@ impl ColorableTerminalLocked {
Self::Stdout(s) => s,
Self::Stderr(s) => s,
#[cfg(feature = "test")]
Self::StyledTestWriter(w) => w,
#[cfg(feature = "test")]
Self::TestWriter(w) => w,
}
}
Expand Down Expand Up @@ -230,7 +242,9 @@ enum TerminalInner {
Stdout(AutoStream<io::Stdout>),
Stderr(AutoStream<io::Stderr>),
#[cfg(feature = "test")]
TestWriter(TestWriter),
StyledTestWriter(TestWriter),
#[cfg(feature = "test")]
TestWriter(StripStream<TestWriter>),
}

/// Select what stream to make a terminal on
Expand Down
21 changes: 21 additions & 0 deletions tests/suite/cli_rustup_ui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::fs::create_dir_all;
use std::path::Path;

use rustup::test::{CliTestContext, Scenario};
use snapbox::Data;
use snapbox::cmd::{Command, cargo_bin};

Expand Down Expand Up @@ -240,6 +241,26 @@ fn rustup_set_cmd_profile_cmd_help_flag() {
);
}

#[tokio::test]
async fn rustup_show_toolchain() {
let name = "rustup_show_toolchain";
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "default", "nightly"])
.await
.is_ok();
cx.config
.expect_with_env(["rustup", "show"], [("RUSTUP_TERM_COLOR", "always")])
.await
.extend_redactions([("[RUSTUP_DIR]", &cx.config.rustupdir.to_string())])
.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_show_cmd_help_flag() {
test_help("rustup_show_cmd_help_flag", &["show", "--help"]);
Expand Down
52 changes: 52 additions & 0 deletions tests/suite/cli_rustup_ui/rustup_show_toolchain.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.
Loading