Skip to content

Commit

Permalink
Implement verbose option for rustup toolchain list
Browse files Browse the repository at this point in the history
Update verbose option for toolchain list

Correct toolchain list tests w. verbose option
  • Loading branch information
BeniCheni committed Sep 14, 2019
1 parent ec6d1af commit 6bd2ffd
Show file tree
Hide file tree
Showing 4 changed files with 49 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
19 changes: 17 additions & 2 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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 @@ -217,7 +217,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 infomation")
.takes_value(false)
.short("v")
.long("verbose"),
)
)
.subcommand(
SubCommand::with_name("install")
.about("Install or update a given toolchain")
Expand Down Expand Up @@ -1020,6 +1030,11 @@ fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches<'_>) -> Result<Too
Ok(toolchain)
}

fn toolchain_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
let is_verbose = if m.is_present("verbose") { true } else { false };
return common::list_toolchains(cfg, is_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 6bd2ffd

Please sign in to comment.