Skip to content

Commit 0ec2dbe

Browse files
authored
Merge pull request #1988 from BeniCheni/toolchain-list-verbose
Implement verbose option for "rustup toolchain list"
2 parents d84e6e5 + 5406e6f commit 0ec2dbe

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

src/cli/common.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,13 @@ pub fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<()> {
424424
Ok(())
425425
}
426426

427-
pub fn list_toolchains(cfg: &Cfg) -> Result<()> {
427+
pub fn list_toolchains(cfg: &Cfg, is_verbose: bool) -> Result<()> {
428428
let toolchains = cfg.list_toolchains()?;
429+
let toolchain_info = if is_verbose {
430+
format!("\t{}", &cfg.rustup_dir.display())
431+
} else {
432+
String::from("")
433+
};
429434

430435
if toolchains.is_empty() {
431436
println!("no installed toolchains");
@@ -436,11 +441,11 @@ pub fn list_toolchains(cfg: &Cfg) -> Result<()> {
436441
} else {
437442
""
438443
};
439-
println!("{}{}", &toolchain, if_default);
444+
println!("{}{}{}", &toolchain, if_default, toolchain_info);
440445
}
441446
} else {
442447
for toolchain in toolchains {
443-
println!("{}", &toolchain);
448+
println!("{}{}", &toolchain, toolchain_info);
444449
}
445450
}
446451
Ok(())

src/cli/rustup_mode.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn main() -> Result<()> {
5454
("default", Some(m)) => default_(cfg, m)?,
5555
("toolchain", Some(c)) => match c.subcommand() {
5656
("install", Some(m)) => update(cfg, m)?,
57-
("list", Some(_)) => handle_epipe(common::list_toolchains(cfg))?,
57+
("list", Some(m)) => handle_epipe(toolchain_list(cfg, m))?,
5858
("link", Some(m)) => toolchain_link(cfg, m)?,
5959
("uninstall", Some(m)) => toolchain_remove(cfg, m)?,
6060
(_, _) => unreachable!(),
@@ -222,7 +222,17 @@ pub fn cli() -> App<'static, 'static> {
222222
.setting(AppSettings::VersionlessSubcommands)
223223
.setting(AppSettings::DeriveDisplayOrder)
224224
.setting(AppSettings::SubcommandRequiredElseHelp)
225-
.subcommand(SubCommand::with_name("list").about("List installed toolchains"))
225+
.subcommand(
226+
SubCommand::with_name("list")
227+
.about("List installed toolchains")
228+
.arg(
229+
Arg::with_name("verbose")
230+
.help("Enable verbose output with toolchain information")
231+
.takes_value(false)
232+
.short("v")
233+
.long("verbose"),
234+
)
235+
)
226236
.subcommand(
227237
SubCommand::with_name("install")
228238
.about("Install or update a given toolchain")
@@ -1067,6 +1077,10 @@ fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches<'_>) -> Result<Too
10671077
Ok(toolchain)
10681078
}
10691079

1080+
fn toolchain_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
1081+
common::list_toolchains(cfg, m.is_present("verbose"))
1082+
}
1083+
10701084
fn toolchain_link(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
10711085
let toolchain = m.value_of("toolchain").expect("");
10721086
let path = m.value_of("path").expect("");

tests/cli-v1.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,19 @@ fn list_toolchains() {
9999
&["rustup", "update", "beta-2015-01-01", "--no-self-update"],
100100
);
101101
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "nightly");
102+
expect_stdout_ok(
103+
config,
104+
&["rustup", "toolchain", "list", "-v"],
105+
"(default)\t",
106+
);
107+
expect_stdout_ok(
108+
config,
109+
&["rustup", "toolchain", "list", "--verbose"],
110+
"(default)\t",
111+
);
102112
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "beta-2015-01-01");
113+
expect_stdout_ok(config, &["rustup", "toolchain", "list", "-v"], "\t");
114+
expect_stdout_ok(config, &["rustup", "toolchain", "list", "--verbose"], "\t");
103115
});
104116
}
105117

tests/cli-v2.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,19 @@ fn list_toolchains() {
102102
&["rustup", "update", "beta-2015-01-01", "--no-self-update"],
103103
);
104104
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "nightly");
105+
expect_stdout_ok(
106+
config,
107+
&["rustup", "toolchain", "list", "-v"],
108+
"(default)\t",
109+
);
110+
expect_stdout_ok(
111+
config,
112+
&["rustup", "toolchain", "list", "--verbose"],
113+
"(default)\t",
114+
);
105115
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "beta-2015-01-01");
116+
expect_stdout_ok(config, &["rustup", "toolchain", "list", "-v"], "\t");
117+
expect_stdout_ok(config, &["rustup", "toolchain", "list", "--verbose"], "\t");
106118
});
107119
}
108120

0 commit comments

Comments
 (0)