Skip to content

Commit c817163

Browse files
committed
Merge list_{,installed_}components functions
1 parent adfcf0f commit c817163

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

src/cli/common.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ pub(crate) fn list_installed_targets(
426426

427427
pub(crate) fn list_components(
428428
distributable: DistributableToolchain<'_>,
429+
installed_only: bool,
429430
) -> Result<utils::ExitCode> {
430431
let mut t = process().stdout().terminal();
431432

@@ -435,28 +436,22 @@ pub(crate) fn list_components(
435436
let components = manifest.query_components(distributable.desc(), &config)?;
436437
for component in components {
437438
let name = component.name;
438-
if component.installed {
439-
t.attr(terminalsource::Attr::Bold)?;
440-
writeln!(t.lock(), "{name} (installed)")?;
441-
t.reset()?;
442-
} else if component.available {
443-
writeln!(t.lock(), "{name}")?;
439+
match (component.available, component.installed, installed_only) {
440+
(false, _, _) | (_, false, true) => continue,
441+
(true, true, false) => {
442+
t.attr(terminalsource::Attr::Bold)?;
443+
writeln!(t.lock(), "{name} (installed)")?;
444+
t.reset()?;
445+
}
446+
(true, _, false) | (_, true, true) => {
447+
writeln!(t.lock(), "{name}")?;
448+
}
444449
}
445450
}
446451

447452
Ok(utils::ExitCode(0))
448453
}
449454

450-
pub(crate) fn list_installed_components(distributable: DistributableToolchain<'_>) -> Result<()> {
451-
let t = process().stdout();
452-
for component in distributable.components()? {
453-
if component.installed {
454-
writeln!(t.lock(), "{}", component.name)?;
455-
}
456-
}
457-
Ok(())
458-
}
459-
460455
fn print_toolchain_path(
461456
cfg: &Cfg,
462457
toolchain: &str,

src/cli/rustup_mode.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,12 +1364,7 @@ fn component_list(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
13641364
let toolchain = explicit_desc_or_dir_toolchain(cfg, m)?;
13651365
// downcasting required because the toolchain files can name any toolchain
13661366
let distributable = (&toolchain).try_into()?;
1367-
1368-
if m.get_flag("installed") {
1369-
common::list_installed_components(distributable)?;
1370-
} else {
1371-
common::list_components(distributable)?;
1372-
}
1367+
common::list_components(distributable, m.get_flag("installed"))?;
13731368
Ok(utils::ExitCode(0))
13741369
}
13751370

0 commit comments

Comments
 (0)