Skip to content

Commit ffcf901

Browse files
authored
Merge pull request #2992 from Enselic/show-verbose
Support `--verbose` for `rustup show`
2 parents 3ced044 + bf060c4 commit ffcf901

File tree

2 files changed

+62
-16
lines changed

2 files changed

+62
-16
lines changed

src/cli/rustup_mode.rs

Lines changed: 26 additions & 16 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)?,
@@ -214,10 +214,7 @@ pub(crate) fn cli() -> App<'static, 'static> {
214214
.setting(AppSettings::DeriveDisplayOrder)
215215
.setting(AppSettings::SubcommandRequiredElseHelp)
216216
.arg(
217-
Arg::with_name("verbose")
218-
.help("Enable verbose output")
219-
.short("v")
220-
.long("verbose"),
217+
verbose_arg("Enable verbose output"),
221218
)
222219
.arg(
223220
Arg::with_name("quiet")
@@ -246,18 +243,17 @@ pub(crate) fn cli() -> App<'static, 'static> {
246243
SubCommand::with_name("show")
247244
.about("Show the active and installed toolchains or profiles")
248245
.after_help(SHOW_HELP)
246+
.arg(
247+
verbose_arg("Enable verbose output with rustc information for all installed toolchains"),
248+
)
249249
.setting(AppSettings::VersionlessSubcommands)
250250
.setting(AppSettings::DeriveDisplayOrder)
251251
.subcommand(
252252
SubCommand::with_name("active-toolchain")
253253
.about("Show the active toolchain")
254254
.after_help(SHOW_ACTIVE_TOOLCHAIN_HELP)
255255
.arg(
256-
Arg::with_name("verbose")
257-
.help("Enable verbose output with rustc information")
258-
.takes_value(false)
259-
.short("v")
260-
.long("verbose"),
256+
verbose_arg("Enable verbose output with rustc information"),
261257
),
262258
)
263259
.subcommand(
@@ -360,11 +356,7 @@ pub(crate) fn cli() -> App<'static, 'static> {
360356
SubCommand::with_name("list")
361357
.about("List installed toolchains")
362358
.arg(
363-
Arg::with_name("verbose")
364-
.help("Enable verbose output with toolchain information")
365-
.takes_value(false)
366-
.short("v")
367-
.long("verbose"),
359+
verbose_arg("Enable verbose output with toolchain information"),
368360
),
369361
)
370362
.subcommand(
@@ -746,6 +738,14 @@ pub(crate) fn cli() -> App<'static, 'static> {
746738
)
747739
}
748740

741+
fn verbose_arg<'a, 'b>(help: &'b str) -> Arg<'a, 'b> {
742+
Arg::with_name("verbose")
743+
.help(help)
744+
.takes_value(false)
745+
.short("v")
746+
.long("verbose")
747+
}
748+
749749
fn maybe_upgrade_data(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<bool> {
750750
match m.subcommand() {
751751
("self", Some(c)) => match c.subcommand() {
@@ -1059,7 +1059,9 @@ fn which(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
10591059
Ok(utils::ExitCode(0))
10601060
}
10611061

1062-
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+
10631065
// Print host triple
10641066
{
10651067
let mut t = term2::stdout();
@@ -1133,6 +1135,14 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
11331135
} else {
11341136
writeln!(t, "{}", it)?;
11351137
}
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+
}
11361146
}
11371147
if show_headers {
11381148
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)