Skip to content

Commit d6db55d

Browse files
authored
Merge pull request #2710 from hi-rustin/rustin-patch-show
show active-toolchain with rustc info
2 parents 7421bea + 4a664b7 commit d6db55d

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/cli/rustup_mode.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn main() -> Result<utils::ExitCode> {
131131
Ok(match matches.subcommand() {
132132
("dump-testament", _) => common::dump_testament()?,
133133
("show", Some(c)) => match c.subcommand() {
134-
("active-toolchain", Some(_)) => handle_epipe(show_active_toolchain(cfg))?,
134+
("active-toolchain", Some(m)) => handle_epipe(show_active_toolchain(cfg, m))?,
135135
("home", Some(_)) => handle_epipe(show_rustup_home(cfg))?,
136136
("profile", Some(_)) => handle_epipe(show_profile(cfg))?,
137137
("keys", Some(_)) => handle_epipe(show_keys(cfg))?,
@@ -243,7 +243,14 @@ pub fn cli() -> App<'static, 'static> {
243243
.subcommand(
244244
SubCommand::with_name("active-toolchain")
245245
.about("Show the active toolchain")
246-
.after_help(SHOW_ACTIVE_TOOLCHAIN_HELP),
246+
.after_help(SHOW_ACTIVE_TOOLCHAIN_HELP)
247+
.arg(
248+
Arg::with_name("verbose")
249+
.help("Enable verbose output with rustc information")
250+
.takes_value(false)
251+
.short("v")
252+
.long("verbose"),
253+
),
247254
)
248255
.subcommand(
249256
SubCommand::with_name("home")
@@ -1182,7 +1189,8 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
11821189
Ok(utils::ExitCode(0))
11831190
}
11841191

1185-
fn show_active_toolchain(cfg: &Cfg) -> Result<utils::ExitCode> {
1192+
fn show_active_toolchain(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
1193+
let verbose = m.is_present("verbose");
11861194
let cwd = utils::current_dir()?;
11871195
match cfg.find_or_install_override_toolchain_or_default(&cwd) {
11881196
Err(crate::Error(crate::ErrorKind::ToolchainNotSelected, _)) => {}
@@ -1193,6 +1201,9 @@ fn show_active_toolchain(cfg: &Cfg) -> Result<utils::ExitCode> {
11931201
} else {
11941202
writeln!(process().stdout(), "{} (default)", toolchain.name())?;
11951203
}
1204+
if verbose {
1205+
writeln!(process().stdout(), "{}", toolchain.rustc_version())?;
1206+
}
11961207
}
11971208
}
11981209
Ok(utils::ExitCode(0))

tests/cli-rustup.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,23 @@ fn show_active_toolchain() {
10821082
});
10831083
}
10841084

1085+
#[test]
1086+
fn show_active_toolchain_with_verbose() {
1087+
setup(&|config| {
1088+
expect_ok(config, &["rustup", "default", "nightly"]);
1089+
expect_ok_ex(
1090+
config,
1091+
&["rustup", "show", "active-toolchain", "--verbose"],
1092+
for_host!(
1093+
r"nightly-{0} (default)
1094+
1.3.0 (hash-nightly-2)
1095+
"
1096+
),
1097+
r"",
1098+
);
1099+
});
1100+
}
1101+
10851102
#[test]
10861103
fn show_active_toolchain_with_override() {
10871104
setup(&|config| {

0 commit comments

Comments
 (0)