Skip to content

Commit 170d711

Browse files
authored
Merge pull request #1659 from naftulikay/feature/component-list-installed
Add Listing of Installed Components
2 parents 37fd750 + 8f58bb0 commit 170d711

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

src/rustup-cli/common.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,21 +323,31 @@ pub fn list_components(toolchain: &Toolchain<'_>) -> Result<()> {
323323
for component in toolchain.list_components()? {
324324
let name = component.name;
325325
if component.required {
326-
let _ = t.attr(term2::Attr::Bold);
327-
let _ = writeln!(t, "{} (default)", name);
328-
let _ = t.reset();
326+
t.attr(term2::Attr::Bold)?;
327+
writeln!(t, "{} (default)", name)?;
328+
t.reset()?;
329329
} else if component.installed {
330-
let _ = t.attr(term2::Attr::Bold);
331-
let _ = writeln!(t, "{} (installed)", name);
332-
let _ = t.reset();
330+
t.attr(term2::Attr::Bold)?;
331+
writeln!(t, "{} (installed)", name)?;
332+
t.reset()?;
333333
} else if component.available {
334-
let _ = writeln!(t, "{}", name);
334+
writeln!(t, "{}", name)?;
335335
}
336336
}
337337

338338
Ok(())
339339
}
340340

341+
pub fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<()> {
342+
let mut t = term2::stdout();
343+
for component in toolchain.list_components()? {
344+
if component.installed {
345+
writeln!(t, "{}", component.name)?;
346+
}
347+
}
348+
Ok(())
349+
}
350+
341351
pub fn list_toolchains(cfg: &Cfg) -> Result<()> {
342352
let toolchains = cfg.list_toolchains()?;
343353

src/rustup-cli/rustup_mode.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ pub fn cli() -> App<'static, 'static> {
293293
.subcommand(
294294
SubCommand::with_name("list")
295295
.about("List installed and available components")
296+
.arg(
297+
Arg::with_name("installed")
298+
.long("--installed")
299+
.help("List only installed components"),
300+
)
296301
.arg(
297302
Arg::with_name("toolchain")
298303
.help(TOOLCHAIN_ARG_HELP)
@@ -823,7 +828,11 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
823828
fn component_list(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
824829
let toolchain = explicit_or_dir_toolchain(cfg, m)?;
825830

826-
common::list_components(&toolchain)
831+
if m.is_present("installed") {
832+
common::list_installed_components(&toolchain)
833+
} else {
834+
common::list_components(&toolchain)
835+
}
827836
}
828837

829838
fn component_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {

0 commit comments

Comments
 (0)