Skip to content

Commit fd0d2ce

Browse files
committed
Merge list_{,installed_}targets
1 parent c817163 commit fd0d2ce

File tree

2 files changed

+15
-36
lines changed

2 files changed

+15
-36
lines changed

src/cli/common.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -375,36 +375,11 @@ where
375375
Ok(utils::ExitCode(0))
376376
}
377377

378-
pub(crate) fn list_targets(distributable: DistributableToolchain<'_>) -> Result<utils::ExitCode> {
379-
let mut t = process().stdout().terminal();
380-
let manifestation = distributable.get_manifestation()?;
381-
let config = manifestation.read_config()?.unwrap_or_default();
382-
let manifest = distributable.get_manifest()?;
383-
let components = manifest.query_components(distributable.desc(), &config)?;
384-
for component in components {
385-
if component.component.short_name_in_manifest() == "rust-std" {
386-
let target = component
387-
.component
388-
.target
389-
.as_ref()
390-
.expect("rust-std should have a target");
391-
if component.installed {
392-
let _ = t.attr(terminalsource::Attr::Bold);
393-
let _ = writeln!(t.lock(), "{target} (installed)");
394-
let _ = t.reset();
395-
} else if component.available {
396-
let _ = writeln!(t.lock(), "{target}");
397-
}
398-
}
399-
}
400-
401-
Ok(utils::ExitCode(0))
402-
}
403-
404-
pub(crate) fn list_installed_targets(
378+
pub(crate) fn list_targets(
405379
distributable: DistributableToolchain<'_>,
380+
installed_only: bool,
406381
) -> Result<utils::ExitCode> {
407-
let t = process().stdout();
382+
let mut t = process().stdout().terminal();
408383
let manifestation = distributable.get_manifestation()?;
409384
let config = manifestation.read_config()?.unwrap_or_default();
410385
let manifest = distributable.get_manifest()?;
@@ -416,11 +391,20 @@ pub(crate) fn list_installed_targets(
416391
.target
417392
.as_ref()
418393
.expect("rust-std should have a target");
419-
if component.installed {
420-
writeln!(t.lock(), "{target}")?;
394+
match (component.available, component.installed, installed_only) {
395+
(false, _, _) | (_, false, true) => continue,
396+
(true, true, false) => {
397+
t.attr(terminalsource::Attr::Bold)?;
398+
writeln!(t.lock(), "{target} (installed)")?;
399+
t.reset()?;
400+
}
401+
(true, _, false) | (_, true, true) => {
402+
writeln!(t.lock(), "{target}")?;
403+
}
421404
}
422405
}
423406
}
407+
424408
Ok(utils::ExitCode(0))
425409
}
426410

src/cli/rustup_mode.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,12 +1266,7 @@ fn target_list(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
12661266
let toolchain = explicit_desc_or_dir_toolchain(cfg, m)?;
12671267
// downcasting required because the toolchain files can name any toolchain
12681268
let distributable = (&toolchain).try_into()?;
1269-
1270-
if m.get_flag("installed") {
1271-
common::list_installed_targets(distributable)
1272-
} else {
1273-
common::list_targets(distributable)
1274-
}
1269+
common::list_targets(distributable, m.get_flag("installed"))
12751270
}
12761271

12771272
fn target_add(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {

0 commit comments

Comments
 (0)