From 8f58bb08214d233649f87bb7b64c5bd5a133ba19 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 14 Feb 2019 21:25:39 +0000 Subject: [PATCH] Add Listing of Installed Components This feature adds the ability to only list installed components rather than all available components. --- src/rustup-cli/common.rs | 24 +++++++++++++++++------- src/rustup-cli/rustup_mode.rs | 11 ++++++++++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/rustup-cli/common.rs b/src/rustup-cli/common.rs index a6a04474eb..d4ee5d038c 100644 --- a/src/rustup-cli/common.rs +++ b/src/rustup-cli/common.rs @@ -323,21 +323,31 @@ pub fn list_components(toolchain: &Toolchain<'_>) -> Result<()> { for component in toolchain.list_components()? { let name = component.name; if component.required { - let _ = t.attr(term2::Attr::Bold); - let _ = writeln!(t, "{} (default)", name); - let _ = t.reset(); + t.attr(term2::Attr::Bold)?; + writeln!(t, "{} (default)", name)?; + t.reset()?; } else if component.installed { - let _ = t.attr(term2::Attr::Bold); - let _ = writeln!(t, "{} (installed)", name); - let _ = t.reset(); + t.attr(term2::Attr::Bold)?; + writeln!(t, "{} (installed)", name)?; + t.reset()?; } else if component.available { - let _ = writeln!(t, "{}", name); + writeln!(t, "{}", name)?; } } Ok(()) } +pub fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<()> { + let mut t = term2::stdout(); + for component in toolchain.list_components()? { + if component.installed { + writeln!(t, "{}", component.name)?; + } + } + Ok(()) +} + pub fn list_toolchains(cfg: &Cfg) -> Result<()> { let toolchains = cfg.list_toolchains()?; diff --git a/src/rustup-cli/rustup_mode.rs b/src/rustup-cli/rustup_mode.rs index b923657a02..64104ad31e 100644 --- a/src/rustup-cli/rustup_mode.rs +++ b/src/rustup-cli/rustup_mode.rs @@ -293,6 +293,11 @@ pub fn cli() -> App<'static, 'static> { .subcommand( SubCommand::with_name("list") .about("List installed and available components") + .arg( + Arg::with_name("installed") + .long("--installed") + .help("List only installed components"), + ) .arg( Arg::with_name("toolchain") .help(TOOLCHAIN_ARG_HELP) @@ -823,7 +828,11 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { fn component_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> { let toolchain = explicit_or_dir_toolchain(cfg, m)?; - common::list_components(&toolchain) + if m.is_present("installed") { + common::list_installed_components(&toolchain) + } else { + common::list_components(&toolchain) + } } fn component_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {