From d01c9fb6d3b789a561eb33c270552d2943611e9c Mon Sep 17 00:00:00 2001 From: Benjamin Chen Date: Mon, 9 Sep 2019 10:45:08 -0400 Subject: [PATCH] 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 --- src/cli/common.rs | 11 ++++++++--- src/cli/rustup_mode.rs | 19 +++++++++++++++++-- tests/cli-v1.rs | 12 ++++++++++++ tests/cli-v2.rs | 12 ++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/cli/common.rs b/src/cli/common.rs index 03ed42208a1..46cb881d1e7 100644 --- a/src/cli/common.rs +++ b/src/cli/common.rs @@ -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"); @@ -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(()) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index bcb3933790c..ddf01057600 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -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!(), @@ -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") @@ -1020,6 +1030,11 @@ fn explicit_or_dir_toolchain<'a>(cfg: &'a Cfg, m: &ArgMatches<'_>) -> Result) -> Result<()> { + let is_verbose = m.is_present("verbose"); + 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(""); diff --git a/tests/cli-v1.rs b/tests/cli-v1.rs index 7b0d9e82bb6..39fd8fbf9b2 100644 --- a/tests/cli-v1.rs +++ b/tests/cli-v1.rs @@ -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"); }); } diff --git a/tests/cli-v2.rs b/tests/cli-v2.rs index 4dd5c7813f5..8203e0f3349 100644 --- a/tests/cli-v2.rs +++ b/tests/cli-v2.rs @@ -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"); }); }