Skip to content

Commit

Permalink
Implement verbose option for rustup toolchain list
Browse files Browse the repository at this point in the history
  • Loading branch information
BeniCheni committed Sep 9, 2019
1 parent c6ff944 commit 763dc73
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::errors::*;
use crate::self_update;
use crate::term2;
use clap::ArgMatches;
use git_testament::{git_testament, render_testament};
use lazy_static::lazy_static;
use rustup::utils::notify::NotificationLevel;
Expand Down Expand Up @@ -432,8 +433,14 @@ pub fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<()> {
Ok(())
}

pub fn list_toolchains(cfg: &Cfg) -> Result<()> {
pub fn list_toolchains(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
let toolchains = cfg.list_toolchains()?;
let is_verbose = m.is_present("verbose");
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 @@ -444,11 +451,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
14 changes: 12 additions & 2 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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(common::list_toolchains(cfg, m))?,
("link", Some(m)) => toolchain_link(cfg, m)?,
("uninstall", Some(m)) => toolchain_remove(cfg, m)?,
(_, _) => unreachable!(),
Expand Down Expand Up @@ -214,7 +214,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
16 changes: 16 additions & 0 deletions tests/cli-v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,23 @@ 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"], "nightly");
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "--verbose"],
"nightly",
);
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "beta-2015-01-01");
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "-v"],
"beta-2015-01-01",
);
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "--verbose"],
"beta-2015-01-01",
);
});
}

Expand Down
16 changes: 16 additions & 0 deletions tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,23 @@ 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"], "nightly");
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "--verbose"],
"nightly",
);
expect_stdout_ok(config, &["rustup", "toolchain", "list"], "beta-2015-01-01");
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "-v"],
"beta-2015-01-01",
);
expect_stdout_ok(
config,
&["rustup", "toolchain", "list", "--verbose"],
"beta-2015-01-01",
);
});
}

Expand Down

0 comments on commit 763dc73

Please sign in to comment.