mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Rename find_dep_in_package to identical
This commit is contained in:
parent
9af51ae20d
commit
72902f8d57
2 changed files with 16 additions and 10 deletions
|
|
@ -11,7 +11,7 @@ pub(crate) struct Dependency {
|
||||||
pub(crate) name: String, // child.yazi
|
pub(crate) name: String, // child.yazi
|
||||||
|
|
||||||
pub(crate) parent: String, // owner/repo
|
pub(crate) parent: String, // owner/repo
|
||||||
pub(crate) child: String, // child
|
pub(crate) child: String, // child.yazi
|
||||||
|
|
||||||
pub(crate) rev: String,
|
pub(crate) rev: String,
|
||||||
pub(crate) hash: String,
|
pub(crate) hash: String,
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,12 @@ impl Package {
|
||||||
|
|
||||||
pub(crate) async fn add(&mut self, use_: &str) -> Result<()> {
|
pub(crate) async fn add(&mut self, use_: &str) -> Result<()> {
|
||||||
let mut dep = Dependency::from_str(use_)?;
|
let mut dep = Dependency::from_str(use_)?;
|
||||||
|
if let Some(d) = self.identical(&dep) {
|
||||||
if let Some(existing_dep) = self.find_dep_in_package(&dep) {
|
bail!(
|
||||||
let package_type = if existing_dep.is_flavor { "Flavor" } else { "Plugin" };
|
"{} `{}` already exists in package.toml",
|
||||||
bail!("{} `{}` already exists in package.toml", package_type, dep.name)
|
if d.is_flavor { "Flavor" } else { "Plugin" },
|
||||||
|
dep.name
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
dep.add().await?;
|
dep.add().await?;
|
||||||
|
|
@ -45,7 +47,7 @@ impl Package {
|
||||||
pub(crate) async fn delete(&mut self, use_: &str) -> Result<()> {
|
pub(crate) async fn delete(&mut self, use_: &str) -> Result<()> {
|
||||||
let dep_to_find = Dependency::from_str(use_)?;
|
let dep_to_find = Dependency::from_str(use_)?;
|
||||||
|
|
||||||
let dep = match self.find_dep_in_package(&dep_to_find) {
|
let dep = match self.identical(&dep_to_find) {
|
||||||
Some(d) => d,
|
Some(d) => d,
|
||||||
None => bail!("`{}` was not found in package.toml", use_),
|
None => bail!("`{}` was not found in package.toml", use_),
|
||||||
};
|
};
|
||||||
|
|
@ -184,12 +186,16 @@ impl Package {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn find_dep_in_package(&self, dep: &Dependency) -> Option<&Dependency> {
|
fn toml() -> PathBuf { Xdg::config_dir().join("package.toml") }
|
||||||
self.plugins.iter().chain(self.flavors.iter()).find(|d| d.use_ == dep.use_)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn toml() -> PathBuf { Xdg::config_dir().join("package.toml") }
|
fn identical(&self, dep: &Dependency) -> Option<&Dependency> {
|
||||||
|
self
|
||||||
|
.plugins
|
||||||
|
.iter()
|
||||||
|
.chain(&self.flavors)
|
||||||
|
.find(|d| d.parent == dep.parent && d.child == dep.child)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for Package {
|
impl<'de> Deserialize<'de> for Package {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue