Skip to content

Commit bf060c4

Browse files
committed
Support --verbose for rustup show
Which prints rustc info for each installed toolchain. See added test for example output.
1 parent 3f3a1a9 commit bf060c4

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/cli/rustup_mode.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub fn main() -> Result<utils::ExitCode> {
142142
("home", Some(_)) => handle_epipe(show_rustup_home(cfg))?,
143143
("profile", Some(_)) => handle_epipe(show_profile(cfg))?,
144144
("keys", Some(_)) => handle_epipe(show_keys(cfg))?,
145-
(_, _) => handle_epipe(show(cfg))?,
145+
(_, _) => handle_epipe(show(cfg, c))?,
146146
},
147147
("install", Some(m)) => deprecated("toolchain install", cfg, m, update)?,
148148
("update", Some(m)) => update(cfg, m)?,
@@ -243,6 +243,9 @@ pub(crate) fn cli() -> App<'static, 'static> {
243243
SubCommand::with_name("show")
244244
.about("Show the active and installed toolchains or profiles")
245245
.after_help(SHOW_HELP)
246+
.arg(
247+
verbose_arg("Enable verbose output with rustc information for all installed toolchains"),
248+
)
246249
.setting(AppSettings::VersionlessSubcommands)
247250
.setting(AppSettings::DeriveDisplayOrder)
248251
.subcommand(
@@ -1056,7 +1059,9 @@ fn which(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
10561059
Ok(utils::ExitCode(0))
10571060
}
10581061

1059-
fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
1062+
fn show(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
1063+
let verbose = m.is_present("verbose");
1064+
10601065
// Print host triple
10611066
{
10621067
let mut t = term2::stdout();
@@ -1130,6 +1135,14 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
11301135
} else {
11311136
writeln!(t, "{}", it)?;
11321137
}
1138+
if verbose {
1139+
if let Ok(toolchain) = cfg.get_toolchain(&it, false) {
1140+
writeln!(process().stdout(), "{}", toolchain.rustc_version())?;
1141+
}
1142+
// To make it easy to see what rustc that belongs to what
1143+
// toolchain we separate each pair with an extra newline
1144+
writeln!(process().stdout())?;
1145+
}
11331146
}
11341147
if show_headers {
11351148
writeln!(t)?

tests/cli-rustup.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,42 @@ fn show_active_toolchain() {
10671067
});
10681068
}
10691069

1070+
#[test]
1071+
fn show_with_verbose() {
1072+
setup(&|config| {
1073+
expect_ok(config, &["rustup", "default", "nightly"]);
1074+
expect_ok(config, &["rustup", "update", "nightly-2015-01-01"]);
1075+
expect_ok_ex(
1076+
config,
1077+
&["rustup", "show", "--verbose"],
1078+
for_host_and_home!(
1079+
config,
1080+
r"Default host: {0}
1081+
rustup home: {1}
1082+
1083+
installed toolchains
1084+
--------------------
1085+
1086+
nightly-2015-01-01-{0}
1087+
1.2.0 (hash-nightly-1)
1088+
1089+
nightly-{0} (default)
1090+
1.3.0 (hash-nightly-2)
1091+
1092+
1093+
active toolchain
1094+
----------------
1095+
1096+
nightly-{0} (default)
1097+
1.3.0 (hash-nightly-2)
1098+
1099+
"
1100+
),
1101+
r"",
1102+
);
1103+
});
1104+
}
1105+
10701106
#[test]
10711107
fn show_active_toolchain_with_verbose() {
10721108
setup(&|config| {

0 commit comments

Comments
 (0)