Skip to content

Commit

Permalink
Merge pull request #2992 from Enselic/show-verbose
Browse files Browse the repository at this point in the history
Support `--verbose` for `rustup show`
  • Loading branch information
kinnison authored Jun 4, 2022
2 parents 3ced044 + bf060c4 commit ffcf901
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub fn main() -> Result<utils::ExitCode> {
("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)?,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -246,18 +243,17 @@ 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(
SubCommand::with_name("active-toolchain")
.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(
Expand Down Expand Up @@ -360,11 +356,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(
Expand Down Expand Up @@ -746,6 +738,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<bool> {
match m.subcommand() {
("self", Some(c)) => match c.subcommand() {
Expand Down Expand Up @@ -1059,7 +1059,9 @@ fn which(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
Ok(utils::ExitCode(0))
}

fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
fn show(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
let verbose = m.is_present("verbose");

// Print host triple
{
let mut t = term2::stdout();
Expand Down Expand Up @@ -1133,6 +1135,14 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
} 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)?
Expand Down
36 changes: 36 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down

0 comments on commit ffcf901

Please sign in to comment.