Skip to content

Commit 5406e6f

Browse files
committed
Implement verbose option for rustup toolchain list
Update verbose option for toolchain list Correct toolchain list tests w. verbose option Update syntax based on clippy Simplify toolchain_list fn in rustup_mode.rs Correct typo in list subcommand
1 parent ec6d1af commit 5406e6f

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
@@ -53,7 +53,7 @@ pub fn main() -> Result<()> {
5353
("default", Some(m)) => default_(cfg, m)?,
5454
("toolchain", Some(c)) => match c.subcommand() {
5555
("install", Some(m)) => update(cfg, m)?,
56-
("list", Some(_)) => handle_epipe(common::list_toolchains(cfg))?,
56+
("list", Some(m)) => handle_epipe(toolchain_list(cfg, m))?,
5757
("link", Some(m)) => toolchain_link(cfg, m)?,
5858
("uninstall", Some(m)) => toolchain_remove(cfg, m)?,
5959
(_, _) => unreachable!(),
@@ -217,7 +217,17 @@ pub fn cli() -> App<'static, 'static> {
217217
.setting(AppSettings::VersionlessSubcommands)
218218
.setting(AppSettings::DeriveDisplayOrder)
219219
.setting(AppSettings::SubcommandRequiredElseHelp)
220-
.subcommand(SubCommand::with_name("list").about("List installed toolchains"))
220+
.subcommand(
221+
SubCommand::with_name("list")
222+
.about("List installed toolchains")
223+
.arg(
224+
Arg::with_name("verbose")
225+
.help("Enable verbose output with toolchain information")
226+
.takes_value(false)
227+
.short("v")
228+
.long("verbose"),
229+
)
230+
)
221231
.subcommand(
222232
SubCommand::with_name("install")
223233
.about("Install or update a given toolchain")
@@ -1020,6 +1030,10 @@ fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches<'_>) -> Result<Too
10201030
Ok(toolchain)
10211031
}
10221032

1033+
fn toolchain_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
1034+
common::list_toolchains(cfg, m.is_present("verbose"))
1035+
}
1036+
10231037
fn toolchain_link(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
10241038
let toolchain = m.value_of("toolchain").expect("");
10251039
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)