Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support --verbose for rustup show #2992

Merged
merged 2 commits into from
Jun 4, 2022
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
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