Skip to content

Commit

Permalink
Deduplicate code to get components from distributable
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed May 7, 2024
1 parent fd0d2ce commit 170ce65
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 35 deletions.
13 changes: 2 additions & 11 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,7 @@ pub(crate) fn list_targets(
installed_only: bool,
) -> Result<utils::ExitCode> {
let mut t = process().stdout().terminal();
let manifestation = distributable.get_manifestation()?;
let config = manifestation.read_config()?.unwrap_or_default();
let manifest = distributable.get_manifest()?;
let components = manifest.query_components(distributable.desc(), &config)?;
for component in components {
for component in distributable.components()? {
if component.component.short_name_in_manifest() == "rust-std" {
let target = component
.component
Expand Down Expand Up @@ -413,12 +409,7 @@ pub(crate) fn list_components(
installed_only: bool,
) -> Result<utils::ExitCode> {
let mut t = process().stdout().terminal();

let manifestation = distributable.get_manifestation()?;
let config = manifestation.read_config()?.unwrap_or_default();
let manifest = distributable.get_manifest()?;
let components = manifest.query_components(distributable.desc(), &config)?;
for component in components {
for component in distributable.components()? {
let name = component.name;
match (component.available, component.installed, installed_only) {
(false, _, _) | (_, false, true) => continue,
Expand Down
22 changes: 4 additions & 18 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,14 +1084,7 @@ fn show(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
// active_toolchain will carry the reason we don't have one in its detail.
let active_targets = if let Ok(ref at) = active_toolchain {
if let Ok(distributable) = DistributableToolchain::try_from(&at.0) {
let components = (|| {
let manifestation = distributable.get_manifestation()?;
let config = manifestation.read_config()?.unwrap_or_default();
let manifest = distributable.get_manifest()?;
manifest.query_components(distributable.desc(), &config)
})();

match components {
match distributable.components() {
Ok(cs_vec) => cs_vec
.into_iter()
.filter(|c| c.component.short_name_in_manifest() == "rust-std")
Expand Down Expand Up @@ -1277,11 +1270,7 @@ fn target_add(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
// list_components *and* add_component would both be inappropriate for
// custom toolchains.
let distributable = DistributableToolchain::try_from(&toolchain)?;
let manifestation = distributable.get_manifestation()?;
let config = manifestation.read_config()?.unwrap_or_default();
let manifest = distributable.get_manifest()?;
let components = manifest.query_components(distributable.desc(), &config)?;

let components = distributable.components()?;
let mut targets: Vec<_> = m
.get_many::<String>("target")
.unwrap()
Expand Down Expand Up @@ -1554,11 +1543,8 @@ fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
let toolchain = explicit_desc_or_dir_toolchain(cfg, m)?;

if let Ok(distributable) = DistributableToolchain::try_from(&toolchain) {
let manifestation = distributable.get_manifestation()?;
let config = manifestation.read_config()?.unwrap_or_default();
let manifest = distributable.get_manifest()?;
let components = manifest.query_components(distributable.desc(), &config)?;
if let [_] = components
if let [_] = distributable
.components()?
.into_iter()
.filter(|cstatus| {
cstatus.component.short_name_in_manifest() == "rust-docs" && !cstatus.installed
Expand Down
7 changes: 1 addition & 6 deletions src/dist/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,7 @@ impl Component {
distributable: &DistributableToolchain<'_>,
fallback_target: Option<&TargetTriple>,
) -> Result<Self> {
let manifestation = distributable.get_manifestation()?;
let config = manifestation.read_config()?.unwrap_or_default();
let manifest = distributable.get_manifest()?;
let manifest_components = manifest.query_components(distributable.desc(), &config)?;

for component_status in manifest_components {
for component_status in distributable.components()? {
let short_name = component_status.component.short_name_in_manifest();
let target = component_status.component.target.as_ref();

Expand Down

0 comments on commit 170ce65

Please sign in to comment.