refact(rustup): getting switches per repotype
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
use crate::backend::backend_trait::Switches;
|
|
||||||
|
|
||||||
use super::types::{Repotype, RustupPackage};
|
use super::types::{Repotype, RustupPackage};
|
||||||
|
|
||||||
pub fn toolchain_of_component_was_already_removed(
|
pub fn toolchain_of_component_was_already_removed(
|
||||||
@@ -25,27 +23,6 @@ pub fn sort_packages_into_toolchains_and_components(
|
|||||||
(toolchains, components)
|
(toolchains, components)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_install_switches(repotype: Repotype) -> Switches {
|
|
||||||
match repotype {
|
|
||||||
Repotype::Toolchain => &["toolchain", "install"],
|
|
||||||
Repotype::Component => &["component", "add", "--toolchain"],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_remove_switches(repotype: Repotype) -> Switches {
|
|
||||||
match repotype {
|
|
||||||
Repotype::Toolchain => &["toolchain", "uninstall"],
|
|
||||||
Repotype::Component => &["component", "remove", "--toolchain"],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_info_switches(repotype: Repotype) -> Switches {
|
|
||||||
match repotype {
|
|
||||||
Repotype::Toolchain => &["toolchain", "list"],
|
|
||||||
Repotype::Component => &["component", "list", "--installed", "--toolchain"],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn install_components(line: &str, toolchain: &str, val: &mut Vec<String>) {
|
pub fn install_components(line: &str, toolchain: &str, val: &mut Vec<String>) {
|
||||||
let mut chunks = line.splitn(3, '-');
|
let mut chunks = line.splitn(3, '-');
|
||||||
let component = chunks.next().expect("Component name is empty!");
|
let component = chunks.next().expect("Component name is empty!");
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ impl Backend for Rustup {
|
|||||||
|
|
||||||
fn get_all_installed_packages(&self) -> Result<HashSet<Package>> {
|
fn get_all_installed_packages(&self) -> Result<HashSet<Package>> {
|
||||||
let toolchains_vec = self
|
let toolchains_vec = self
|
||||||
.run_toolchain_command(helpers::get_info_switches(Repotype::Toolchain))
|
.run_toolchain_command(Repotype::Toolchain.get_info_switches())
|
||||||
.context("Getting installed toolchains")?;
|
.context("Getting installed toolchains")?;
|
||||||
|
|
||||||
let toolchains: HashSet<Package> = toolchains_vec
|
let toolchains: HashSet<Package> = toolchains_vec
|
||||||
@@ -38,10 +38,7 @@ impl Backend for Rustup {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let components: HashSet<Package> = self
|
let components: HashSet<Package> = self
|
||||||
.run_component_command(
|
.run_component_command(Repotype::Component.get_install_switches(), &toolchains_vec)
|
||||||
helpers::get_info_switches(Repotype::Component),
|
|
||||||
&toolchains_vec,
|
|
||||||
)
|
|
||||||
.context("Getting installed components")?
|
.context("Getting installed components")?
|
||||||
.iter()
|
.iter()
|
||||||
.map(|name| ["component", name].join("/").into())
|
.map(|name| ["component", name].join("/").into())
|
||||||
@@ -153,7 +150,7 @@ impl Rustup {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let mut cmd = Command::new(self.get_binary());
|
let mut cmd = Command::new(self.get_binary());
|
||||||
cmd.args(helpers::get_install_switches(Repotype::Toolchain));
|
cmd.args(Repotype::Toolchain.get_install_switches());
|
||||||
|
|
||||||
for toolchain in toolchains {
|
for toolchain in toolchains {
|
||||||
cmd.arg(&toolchain.toolchain);
|
cmd.arg(&toolchain.toolchain);
|
||||||
@@ -173,7 +170,7 @@ impl Rustup {
|
|||||||
|
|
||||||
for components_for_one_toolchain in components_by_toolchain {
|
for components_for_one_toolchain in components_by_toolchain {
|
||||||
let mut cmd = Command::new(self.get_binary());
|
let mut cmd = Command::new(self.get_binary());
|
||||||
cmd.args(helpers::get_install_switches(Repotype::Component));
|
cmd.args(Repotype::Component.get_install_switches());
|
||||||
|
|
||||||
let the_toolchain = &components_for_one_toolchain
|
let the_toolchain = &components_for_one_toolchain
|
||||||
.first()
|
.first()
|
||||||
@@ -202,7 +199,7 @@ impl Rustup {
|
|||||||
let mut removed_toolchains = vec![];
|
let mut removed_toolchains = vec![];
|
||||||
if !toolchains.is_empty() {
|
if !toolchains.is_empty() {
|
||||||
let mut cmd = Command::new(self.get_binary());
|
let mut cmd = Command::new(self.get_binary());
|
||||||
cmd.args(helpers::get_remove_switches(Repotype::Toolchain));
|
cmd.args(Repotype::Toolchain.get_remove_switches());
|
||||||
|
|
||||||
for toolchain_package in &toolchains {
|
for toolchain_package in &toolchains {
|
||||||
let name = toolchain_package.toolchain.as_str();
|
let name = toolchain_package.toolchain.as_str();
|
||||||
@@ -223,7 +220,7 @@ impl Rustup {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for component_package in components {
|
for component_package in components {
|
||||||
let mut cmd = Command::new(self.get_binary());
|
let mut cmd = Command::new(self.get_binary());
|
||||||
cmd.args(helpers::get_remove_switches(Repotype::Component));
|
cmd.args(Repotype::Component.get_remove_switches());
|
||||||
|
|
||||||
if helpers::toolchain_of_component_was_already_removed(
|
if helpers::toolchain_of_component_was_already_removed(
|
||||||
&removed_toolchains,
|
&removed_toolchains,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use crate::Package;
|
use crate::{backend::backend_trait::Switches, Package};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Rustup {
|
pub struct Rustup {
|
||||||
@@ -27,6 +27,27 @@ impl Repotype {
|
|||||||
};
|
};
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_install_switches(self) -> Switches {
|
||||||
|
match self {
|
||||||
|
Self::Toolchain => &["toolchain", "install"],
|
||||||
|
Self::Component => &["component", "add", "--toolchain"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_remove_switches(self) -> Switches {
|
||||||
|
match self {
|
||||||
|
Self::Toolchain => &["toolchain", "uninstall"],
|
||||||
|
Self::Component => &["component", "remove", "--toolchain"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_info_switches(self) -> Switches {
|
||||||
|
match self {
|
||||||
|
Self::Toolchain => &["toolchain", "list"],
|
||||||
|
Self::Component => &["component", "list", "--installed", "--toolchain"],
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A package as used exclusively in the rustup backend. Contrary to other packages, this does not
|
/// A package as used exclusively in the rustup backend. Contrary to other packages, this does not
|
||||||
|
|||||||
Reference in New Issue
Block a user