Skip to content

Commit

Permalink
Merge pull request #1988 from BeniCheni/toolchain-list-verbose
Browse files Browse the repository at this point in the history
Implement verbose option for "rustup toolchain list"
  • Loading branch information
kinnison authored Sep 17, 2019
2 parents d84e6e5 + 5406e6f commit 0ec2dbe
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,13 @@ pub fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<()> {
Ok(())
}

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

if toolchains.is_empty() {
println!("no installed toolchains");
Expand All @@ -436,11 +441,11 @@ pub fn list_toolchains(cfg: &Cfg) -> Result<()> {
} else {
""
};
println!("{}{}", &toolchain, if_default);
println!("{}{}{}", &toolchain, if_default, toolchain_info);
}
} else {
for toolchain in toolchains {
println!("{}", &toolchain);
println!("{}{}", &toolchain, toolchain_info);
}
}
Ok(())
Expand Down
18 changes: 16 additions & 2 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn main() -> Result<()> {
("default", Some(m)) => default_(cfg, m)?,
("toolchain", Some(c)) => match c.subcommand() {
("install", Some(m)) => update(cfg, m)?,
("list", Some(_)) => handle_epipe(common::list_toolchains(cfg))?,
("list", Some(m)) => handle_epipe(toolchain_list(cfg, m))?,
("link", Some(m)) => toolchain_link(cfg, m)?,
("uninstall", Some(m)) => toolchain_remove(cfg, m)?,
(_, _) => unreachable!(),
Expand Down Expand Up @@ -222,7 +222,17 @@ pub fn cli() -> App<'static, 'static> {
.setting(AppSettings::VersionlessSubcommands)
.setting(AppSettings::DeriveDisplayOrder)
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(SubCommand::with_name("list").about("List installed toolchains"))
.subcommand(
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"),
)
)
.subcommand(
SubCommand::with_name("install")
.about("Install or update a given toolchain")
Expand Down Expand Up @@ -1067,6 +1077,10 @@ fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches<'_>) -> Result<Too
Ok(toolchain)
}

fn toolchain_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
common::list_toolchains(cfg, m.is_present("verbose"))
}

fn toolchain_link(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
let toolchain = m.value_of("toolchain").expect("");
let path = m.value_of("path").expect("");
Expand Down
12 changes: 12 additions & 0 deletions tests/cli-v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,19 @@ fn list_toolchains() {
&["rustup", "update", "beta-2015-01-01", "--no-self-update"],
);
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "nightly");
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "-v"],
"(default)\t",
);
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "--verbose"],
"(default)\t",
);
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "beta-2015-01-01");
expect_stdout_ok(config, &["rustup", "toolchain", "list", "-v"], "\t");
expect_stdout_ok(config, &["rustup", "toolchain", "list", "--verbose"], "\t");
});
}

Expand Down
12 changes: 12 additions & 0 deletions tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,19 @@ fn list_toolchains() {
&["rustup", "update", "beta-2015-01-01", "--no-self-update"],
);
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "nightly");
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "-v"],
"(default)\t",
);
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "--verbose"],
"(default)\t",
);
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "beta-2015-01-01");
expect_stdout_ok(config, &["rustup", "toolchain", "list", "-v"], "\t");
expect_stdout_ok(config, &["rustup", "toolchain", "list", "--verbose"], "\t");
});
}

Expand Down

0 comments on commit 0ec2dbe

Please sign in to comment.