From 3f3a1a9faf8ac76c8c103c9bd321fee480306a6e Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Thu, 19 May 2022 18:30:24 +0200 Subject: [PATCH 1/2] src/cli/rustup_mode.rs: Add verbose_arg() helper --- src/cli/rustup_mode.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index f7d78979e2..128bad60e0 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -214,10 +214,7 @@ pub(crate) fn cli() -> App<'static, 'static> { .setting(AppSettings::DeriveDisplayOrder) .setting(AppSettings::SubcommandRequiredElseHelp) .arg( - Arg::with_name("verbose") - .help("Enable verbose output") - .short("v") - .long("verbose"), + verbose_arg("Enable verbose output"), ) .arg( Arg::with_name("quiet") @@ -253,11 +250,7 @@ pub(crate) fn cli() -> App<'static, 'static> { .about("Show the active toolchain") .after_help(SHOW_ACTIVE_TOOLCHAIN_HELP) .arg( - Arg::with_name("verbose") - .help("Enable verbose output with rustc information") - .takes_value(false) - .short("v") - .long("verbose"), + verbose_arg("Enable verbose output with rustc information"), ), ) .subcommand( @@ -360,11 +353,7 @@ pub(crate) fn cli() -> App<'static, 'static> { SubCommand::with_name("list") .about("List installed toolchains") .arg( - Arg::with_name("verbose") - .help("Enable verbose output with toolchain information") - .takes_value(false) - .short("v") - .long("verbose"), + verbose_arg("Enable verbose output with toolchain information"), ), ) .subcommand( @@ -746,6 +735,14 @@ pub(crate) fn cli() -> App<'static, 'static> { ) } +fn verbose_arg<'a, 'b>(help: &'b str) -> Arg<'a, 'b> { + Arg::with_name("verbose") + .help(help) + .takes_value(false) + .short("v") + .long("verbose") +} + fn maybe_upgrade_data(cfg: &Cfg, m: &ArgMatches<'_>) -> Result { match m.subcommand() { ("self", Some(c)) => match c.subcommand() { From bf060c49fff3a40f43df6eb61e9050d0714e8aeb Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Thu, 19 May 2022 20:31:51 +0200 Subject: [PATCH 2/2] Support `--verbose` for `rustup show` Which prints rustc info for each installed toolchain. See added test for example output. --- src/cli/rustup_mode.rs | 17 +++++++++++++++-- tests/cli-rustup.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 128bad60e0..c7cdecb75e 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -142,7 +142,7 @@ pub fn main() -> Result { ("home", Some(_)) => handle_epipe(show_rustup_home(cfg))?, ("profile", Some(_)) => handle_epipe(show_profile(cfg))?, ("keys", Some(_)) => handle_epipe(show_keys(cfg))?, - (_, _) => handle_epipe(show(cfg))?, + (_, _) => handle_epipe(show(cfg, c))?, }, ("install", Some(m)) => deprecated("toolchain install", cfg, m, update)?, ("update", Some(m)) => update(cfg, m)?, @@ -243,6 +243,9 @@ pub(crate) fn cli() -> App<'static, 'static> { SubCommand::with_name("show") .about("Show the active and installed toolchains or profiles") .after_help(SHOW_HELP) + .arg( + verbose_arg("Enable verbose output with rustc information for all installed toolchains"), + ) .setting(AppSettings::VersionlessSubcommands) .setting(AppSettings::DeriveDisplayOrder) .subcommand( @@ -1056,7 +1059,9 @@ fn which(cfg: &Cfg, m: &ArgMatches<'_>) -> Result { Ok(utils::ExitCode(0)) } -fn show(cfg: &Cfg) -> Result { +fn show(cfg: &Cfg, m: &ArgMatches<'_>) -> Result { + let verbose = m.is_present("verbose"); + // Print host triple { let mut t = term2::stdout(); @@ -1130,6 +1135,14 @@ fn show(cfg: &Cfg) -> Result { } else { writeln!(t, "{}", it)?; } + if verbose { + if let Ok(toolchain) = cfg.get_toolchain(&it, false) { + writeln!(process().stdout(), "{}", toolchain.rustc_version())?; + } + // To make it easy to see what rustc that belongs to what + // toolchain we separate each pair with an extra newline + writeln!(process().stdout())?; + } } if show_headers { writeln!(t)? diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index 504d0aa0fc..4f15c7f259 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -1067,6 +1067,42 @@ fn show_active_toolchain() { }); } +#[test] +fn show_with_verbose() { + setup(&|config| { + expect_ok(config, &["rustup", "default", "nightly"]); + expect_ok(config, &["rustup", "update", "nightly-2015-01-01"]); + expect_ok_ex( + config, + &["rustup", "show", "--verbose"], + for_host_and_home!( + config, + r"Default host: {0} +rustup home: {1} + +installed toolchains +-------------------- + +nightly-2015-01-01-{0} +1.2.0 (hash-nightly-1) + +nightly-{0} (default) +1.3.0 (hash-nightly-2) + + +active toolchain +---------------- + +nightly-{0} (default) +1.3.0 (hash-nightly-2) + +" + ), + r"", + ); + }); +} + #[test] fn show_active_toolchain_with_verbose() { setup(&|config| {