From 94f188ca1ca32fc7c997a7e286ff4089d9cfaf54 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 | 11 +++++++++++ src/rustup-cli/rustup_mode.rs | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/rustup-cli/common.rs b/src/rustup-cli/common.rs index 56f6418333a..170d9195cfc 100644 --- a/src/rustup-cli/common.rs +++ b/src/rustup-cli/common.rs @@ -339,6 +339,17 @@ pub fn list_components(toolchain: &Toolchain<'_>) -> Result<()> { Ok(()) } +pub fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<()> { + let mut t = term2::stdout(); + for component in toolchain.list_components()? { + if component.installed { + let name = component.name; + let _ = writeln!(t, "{}", 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 960d32940e2..e9d3e5516b3 100644 --- a/src/rustup-cli/rustup_mode.rs +++ b/src/rustup-cli/rustup_mode.rs @@ -291,6 +291,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) @@ -834,7 +839,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<()> {